Merge "Fix swift key generation in python3"
diff --git a/common/clients.py b/common/clients.py
index 9949d3d..58e0fce 100644
--- a/common/clients.py
+++ b/common/clients.py
@@ -149,51 +149,39 @@
         return KeystoneWrapperClient(auth, verify_cert)
 
     def _get_compute_client(self):
-
-        region = self.conf.region
         # Create our default Nova client to use in testing
         return nova_client.Client(
             self.NOVA_API_VERSION,
             session=self.identity_client.session,
             service_type='compute',
             endpoint_type='publicURL',
-            region_name=region,
+            region_name=self.conf.region,
             os_cache=False,
-            insecure=self.insecure,
-            cacert=self.ca_file,
             http_log_debug=True)
 
     def _get_network_client(self):
 
         return neutron_client.Client(
             session=self.identity_client.session,
-            endpoint_type='publicURL',
-            insecure=self.insecure,
-            ca_cert=self.ca_file)
+            service_type='network',
+            region_name=self.conf.region,
+            endpoint_type='publicURL')
 
     def _get_volume_client(self):
-        region = self.conf.region
-        endpoint_type = 'publicURL'
         return cinder_client.Client(
             self.CINDERCLIENT_VERSION,
             session=self.identity_client.session,
-            region_name=region,
-            endpoint_type=endpoint_type,
-            insecure=self.insecure,
-            cacert=self.ca_file,
+            endpoint_type='publicURL',
+            region_name=self.conf.region,
             http_log_debug=True)
 
     def _get_object_client(self):
-        # swiftclient does not support keystone sessions yet
         args = {
             'auth_version': self.auth_version,
-            'tenant_name': self._tenant_name(),
-            'user': self._username(),
-            'key': self.conf.password,
-            'authurl': self.conf.auth_url,
-            'os_options': {'endpoint_type': 'publicURL'},
-            'insecure': self.insecure,
-            'cacert': self.ca_file,
+            'session': self.identity_client.session,
+            'os_options': {'endpoint_type': 'publicURL',
+                           'region_name': self.conf.region,
+                           'service_type': 'object-store'},
         }
         return swift_client.Connection(**args)
 
@@ -206,8 +194,6 @@
         else:
             args = {
                 'session': self.identity_client.session,
-                'insecure': self.insecure,
-                'cacert': self.ca_file,
                 'region_name': self.conf.region,
                 'endpoint_type': 'publicURL',
                 'service_type': 'metering',
diff --git a/functional/test_create_update_neutron_port.py b/functional/test_create_update_neutron_port.py
index 2109012..4e41b35 100644
--- a/functional/test_create_update_neutron_port.py
+++ b/functional/test_create_update_neutron_port.py
@@ -46,117 +46,53 @@
 outputs:
   port_ip:
     value: {get_attr: [port, fixed_ips, 0, ip_address]}
+  mac_address:
+    value: {get_attr: [port, mac_address]}
 '''
 
 
 class UpdatePortTest(functional_base.FunctionalTestsBase):
 
-    def get_port_id_and_ip(self, stack_identifier):
+    def get_port_id_and_outputs(self, stack_identifier):
         resources = self.client.resources.list(stack_identifier)
         port_id = [res.physical_resource_id for res in resources
                    if res.resource_name == 'port']
         stack = self.client.stacks.get(stack_identifier)
         port_ip = self._stack_output(stack, 'port_ip')
-        return port_id[0], port_ip
+        port_mac = self._stack_output(stack, 'mac_address')
+        return port_id[0], port_ip, port_mac
 
-    def test_stack_update_replace_no_ip(self):
-        templ_no_ip = test_template.replace('ip_address: 11.11.11.11', '')
-        # create with default 'mac' parameter
-        stack_identifier = self.stack_create(template=templ_no_ip)
-        _id, _ip = self.get_port_id_and_ip(stack_identifier)
-
-        # Update with another 'mac' parameter
-        parameters = {'mac': '00-00-00-00-AA-AA'}
-        self.update_stack(stack_identifier, templ_no_ip,
-                          parameters=parameters)
-
-        new_id, _ = self.get_port_id_and_ip(stack_identifier)
-        # port id should be different
-        self.assertNotEqual(_id, new_id)
-
-    def test_stack_update_replace_with_ip(self):
-        # create with default 'mac' parameter
+    def test_update_remove_ip(self):
+        # create with defined ip_address
         stack_identifier = self.stack_create(template=test_template)
-
-        _id, _ip = self.get_port_id_and_ip(stack_identifier)
-
-        # Update with another 'mac' parameter
-        parameters = {'mac': '00-00-00-00-AA-AA'}
-
-        # port should be replaced with same ip
-        self.update_stack(stack_identifier, test_template,
-                          parameters=parameters)
-
-        new_id, new_ip = self.get_port_id_and_ip(stack_identifier)
-        # port id should be different, ip should be the same
-        self.assertEqual(_ip, new_ip)
-        self.assertNotEqual(_id, new_id)
-
-    def test_stack_update_replace_with_ip_rollback(self):
-        # create with default 'mac' parameter
-        stack_identifier = self.stack_create(template=test_template)
-
-        _id, _ip = self.get_port_id_and_ip(stack_identifier)
-
-        # Update with another 'mac' parameter
-        parameters = {'mac': '00-00-00-00-AA-AA'}
-
-        # make test resource failing during update
-        fail_template = test_template.replace('fail: False',
-                                              'fail: True')
-        fail_template = fail_template.replace('value: Test1',
-                                              'value: Rollback')
-
-        # port should be replaced with same ip
-        self.update_stack(stack_identifier, fail_template,
-                          parameters=parameters,
-                          expected_status='ROLLBACK_COMPLETE',
-                          disable_rollback=False)
-
-        new_id, new_ip = self.get_port_id_and_ip(stack_identifier)
-        # port id and ip should be the same after rollback
-        self.assertEqual(_ip, new_ip)
-        self.assertEqual(_id, new_id)
-
-    def test_stack_update_replace_with_ip_after_failed_update(self):
-        # create with default 'mac' parameter
-        stack_identifier = self.stack_create(template=test_template)
-
-        _id, _ip = self.get_port_id_and_ip(stack_identifier)
-
-        # Update with another 'mac' parameter
-        parameters = {'mac': '00-00-00-00-AA-AA'}
-
-        # make test resource failing during update
-        fail_template = test_template.replace('fail: False',
-                                              'fail: True')
-        fail_template = fail_template.replace('value: Test1',
-                                              'value: Rollback')
-
-        # port should be replaced with same ip
-        self.update_stack(stack_identifier, fail_template,
-                          parameters=parameters,
-                          expected_status='UPDATE_FAILED')
-
-        # port should be replaced with same ip
-        self.update_stack(stack_identifier, test_template,
-                          parameters=parameters)
-
-        new_id, new_ip = self.get_port_id_and_ip(stack_identifier)
-        # ip should be the same, but port id should be different, because it's
-        # restore replace
-        self.assertEqual(_ip, new_ip)
-        self.assertNotEqual(_id, new_id)
-
-    def test_stack_update_in_place_remove_ip(self):
-        # create with default 'mac' parameter and defined ip_address
-        stack_identifier = self.stack_create(template=test_template)
-        _id, _ip = self.get_port_id_and_ip(stack_identifier)
+        _id, _ip, _mac = self.get_port_id_and_outputs(stack_identifier)
 
         # remove ip_address property and update stack
         templ_no_ip = test_template.replace('ip_address: 11.11.11.11', '')
         self.update_stack(stack_identifier, templ_no_ip)
 
-        new_id, new_ip = self.get_port_id_and_ip(stack_identifier)
+        new_id, new_ip, new_mac = self.get_port_id_and_outputs(
+            stack_identifier)
         # port should be updated with the same id
         self.assertEqual(_id, new_id)
+        self.assertEqual(_mac, new_mac)
+
+    def test_update_with_mac_address(self):
+        # Setup admin clients for updating mac_address
+        self.setup_clients_for_admin()
+
+        # Create with default mac_address and defined ip_address
+        stack_identifier = self.stack_create(template=test_template)
+        _id, _ip, _mac = self.get_port_id_and_outputs(stack_identifier)
+
+        # Update with another 'mac' parameter
+        parameters = {'mac': '00-00-00-00-AA-AA'}
+        self.update_stack(stack_identifier, test_template,
+                          parameters=parameters)
+
+        new_id, new_ip, new_mac = self.get_port_id_and_outputs(
+            stack_identifier)
+        # mac_address should be different
+        self.assertEqual(_id, new_id)
+        self.assertEqual(_ip, new_ip)
+        self.assertNotEqual(_mac, new_mac)
diff --git a/functional/test_os_wait_condition.py b/functional/test_os_wait_condition.py
index 5c1783a..66b182b 100644
--- a/functional/test_os_wait_condition.py
+++ b/functional/test_os_wait_condition.py
@@ -76,7 +76,7 @@
     type: OS::Heat::WaitCondition
     depends_on: instance1
     properties:
-      count: 25
+      count: 12
       handle: {get_resource: wait_handle}
       timeout: {get_param: timeout}
 
diff --git a/functional/test_reload_on_sighup.py b/functional/test_reload_on_sighup.py
index b014f49..d646581 100644
--- a/functional/test_reload_on_sighup.py
+++ b/functional/test_reload_on_sighup.py
@@ -10,6 +10,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import re
+import subprocess
 import time
 
 import eventlet
@@ -26,6 +28,13 @@
         self.config_file = "/etc/heat/heat.conf"
         super(ReloadOnSighupTest, self).setUp()
 
+    def _is_mod_wsgi_daemon(self, service):
+        process = ''.join(['wsgi:', service[:9]]).replace('_', '-')
+        s = subprocess.Popen(["ps", "ax"], stdout=subprocess.PIPE)
+        for x in s.stdout:
+            if re.search(process, x):
+                return True
+
     def _set_config_value(self, service, key, value):
         config = configparser.ConfigParser()
 
@@ -116,11 +125,17 @@
         # revert all the changes made
         self._change_config(service, new_workers, old_workers)
 
+    def _reload_on_sighup(self, service):
+        if not self._is_mod_wsgi_daemon(service):
+            self._reload(service)
+        else:
+            self.skipTest('Skipping Test, Service running under httpd.')
+
     def test_api_reload_on_sighup(self):
-        self._reload('heat_api')
+        self._reload_on_sighup('heat_api')
 
     def test_api_cfn_reload_on_sighup(self):
-        self._reload('heat_api_cfn')
+        self._reload_on_sighup('heat_api_cfn')
 
     def test_api_cloudwatch_on_sighup(self):
-        self._reload('heat_api_cloudwatch')
+        self._reload_on_sighup('heat_api_cloudwatch')