Merge "Split out Neutron networks client"
diff --git a/tempest/api/identity/v2/test_ec2_credentials.py b/tempest/api/identity/v2/test_ec2_credentials.py
index 17963b8..763d8de 100644
--- a/tempest/api/identity/v2/test_ec2_credentials.py
+++ b/tempest/api/identity/v2/test_ec2_credentials.py
@@ -93,7 +93,7 @@
 
         ec2_creds = self.non_admin_client.show_user_ec2_credentials(
             self.creds.credentials.user_id, resp['access']
-        )
+        )["credential"]
         for key in ['access', 'secret', 'user_id', 'tenant_id']:
             self.assertEqual(ec2_creds[key], resp[key])
 
diff --git a/tempest/api/identity/v2/test_users.py b/tempest/api/identity/v2/test_users.py
index 4e5b41d..3b89b66 100644
--- a/tempest/api/identity/v2/test_users.py
+++ b/tempest/api/identity/v2/test_users.py
@@ -56,7 +56,7 @@
 
         # user updates own password
         resp = self.non_admin_client.update_user_own_password(
-            user_id=user_id, new_pass=new_pass, old_pass=old_pass)
+            user_id=user_id, new_pass=new_pass, old_pass=old_pass)['access']
 
         # check authorization with new token
         self.non_admin_token_client.auth_token(resp['token']['id'])
diff --git a/tempest/api/network/test_ports.py b/tempest/api/network/test_ports.py
index e455ad2..321473c 100644
--- a/tempest/api/network/test_ports.py
+++ b/tempest/api/network/test_ports.py
@@ -167,11 +167,19 @@
         port_list = self.client.list_ports(fixed_ips=fixed_ips)
         # Check that we got the desired port
         ports = port_list['ports']
-        self.assertEqual(len(ports), 1)
-        self.assertEqual(ports[0]['id'], port_1['port']['id'])
-        self.assertEqual(ports[0]['fixed_ips'][0]['ip_address'],
-                         port_1_fixed_ip)
-        self.assertEqual(ports[0]['network_id'], network['id'])
+        tenant_ids = set([port['tenant_id'] for port in ports])
+        self.assertEqual(len(tenant_ids), 1,
+                         'Ports from multiple tenants are in the list resp')
+        port_ids = [port['id'] for port in ports]
+        fixed_ips = [port['fixed_ips'] for port in ports]
+        port_ips = []
+        for addr in fixed_ips:
+            port_ips.extend([port['ip_address'] for port in addr])
+
+        port_net_ids = [port['network_id'] for port in ports]
+        self.assertIn(port_1['port']['id'], port_ids)
+        self.assertIn(port_1_fixed_ip, port_ips)
+        self.assertIn(network['id'], port_net_ids)
 
     @test.idempotent_id('5ad01ed0-0e6e-4c5d-8194-232801b15c72')
     def test_port_list_filter_by_router_id(self):
diff --git a/tempest/common/compute.py b/tempest/common/compute.py
index d107ec2..41b0529 100644
--- a/tempest/common/compute.py
+++ b/tempest/common/compute.py
@@ -89,11 +89,14 @@
 
     if volume_backed:
         volume_name = data_utils.rand_name('volume')
-        volume = clients.volumes_client.create_volume(
+        volumes_client = clients.volumes_v2_client
+        if CONF.volume_feature_enabled.api_v1:
+            volumes_client = clients.volumes_client
+        volume = volumes_client.create_volume(
             display_name=volume_name,
             imageRef=image_id)
-        clients.volumes_client.wait_for_volume_status(volume['volume']['id'],
-                                                      'available')
+        volumes_client.wait_for_volume_status(volume['volume']['id'],
+                                              'available')
 
         bd_map_v2 = [{
             'uuid': volume['volume']['id'],
diff --git a/tempest/common/utils/linux/remote_client.py b/tempest/common/utils/linux/remote_client.py
index 9308390..3bead88 100644
--- a/tempest/common/utils/linux/remote_client.py
+++ b/tempest/common/utils/linux/remote_client.py
@@ -171,3 +171,14 @@
         if dhcp_client == 'udhcpc' and not fixed_ip:
             raise ValueError("need to set 'fixed_ip' for udhcpc client")
         return getattr(self, '_renew_lease_' + dhcp_client)(fixed_ip=fixed_ip)
+
+    def mount(self, dev_name, mount_path='/mnt'):
+        cmd_mount = 'sudo mount /dev/%s %s' % (dev_name, mount_path)
+        self.exec_command(cmd_mount)
+
+    def umount(self, mount_path='/mnt'):
+        self.exec_command('sudo umount %s' % mount_path)
+
+    def make_fs(self, dev_name, fs='ext4'):
+        cmd_mkfs = 'sudo /usr/sbin/mke2fs -t %s /dev/%s' % (fs, dev_name)
+        self.exec_command(cmd_mkfs)
diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py
index 0069da1..cafc137 100644
--- a/tempest/scenario/manager.py
+++ b/tempest/scenario/manager.py
@@ -558,6 +558,29 @@
             floating_ip['ip'], thing['id'])
         return floating_ip
 
+    def create_timestamp(self, server_or_ip, dev_name=None, mount_path='/mnt'):
+        ssh_client = self.get_remote_client(server_or_ip)
+        if dev_name is not None:
+            ssh_client.make_fs(dev_name)
+            ssh_client.mount(dev_name)
+        cmd_timestamp = 'sudo sh -c "date > %s/timestamp; sync"' % mount_path
+        ssh_client.exec_command(cmd_timestamp)
+        timestamp = ssh_client.exec_command('sudo cat %s/timestamp'
+                                            % mount_path)
+        if dev_name is not None:
+            ssh_client.umount(mount_path)
+        return timestamp
+
+    def get_timestamp(self, server_or_ip, dev_name=None, mount_path='/mnt'):
+        ssh_client = self.get_remote_client(server_or_ip)
+        if dev_name is not None:
+            ssh_client.mount(dev_name)
+        timestamp = ssh_client.exec_command('sudo cat %s/timestamp'
+                                            % mount_path)
+        if dev_name is not None:
+            ssh_client.umount(mount_path)
+        return timestamp
+
 
 class NetworkScenarioTest(ScenarioTest):
     """Base class for network scenario tests.
diff --git a/tempest/scenario/test_shelve_instance.py b/tempest/scenario/test_shelve_instance.py
index bf4b8e7..dbc9bbb 100644
--- a/tempest/scenario/test_shelve_instance.py
+++ b/tempest/scenario/test_shelve_instance.py
@@ -37,16 +37,6 @@
 
     """
 
-    def _write_timestamp(self, server_or_ip):
-        ssh_client = self.get_remote_client(server_or_ip)
-        ssh_client.exec_command('date > /tmp/timestamp; sync')
-        self.timestamp = ssh_client.exec_command('cat /tmp/timestamp')
-
-    def _check_timestamp(self, server_or_ip):
-        ssh_client = self.get_remote_client(server_or_ip)
-        got_timestamp = ssh_client.exec_command('cat /tmp/timestamp')
-        self.assertEqual(self.timestamp, got_timestamp)
-
     def _shelve_then_unshelve_server(self, server):
         self.servers_client.shelve_server(server['id'])
         offload_time = CONF.compute.shelved_offload_time
@@ -96,18 +86,19 @@
                             floating_ip['id'])
             self.floating_ips_client.associate_floating_ip_to_server(
                 floating_ip['ip'], server['id'])
-            self._write_timestamp(floating_ip['ip'])
+            timestamp = self.create_timestamp(floating_ip['ip'])
         else:
-            self._write_timestamp(server)
+            timestamp = self.create_timestamp(server)
 
         # Prevent bug #1257594 from coming back
         # Unshelve used to boot the instance with the original image, not
         # with the instance snapshot
         self._shelve_then_unshelve_server(server)
         if CONF.compute.use_floatingip_for_ssh:
-            self._check_timestamp(floating_ip['ip'])
+            timestamp2 = self.get_timestamp(floating_ip['ip'])
         else:
-            self._check_timestamp(server)
+            timestamp2 = self.get_timestamp(server)
+        self.assertEqual(timestamp, timestamp2)
 
     @test.idempotent_id('1164e700-0af0-4a4c-8792-35909a88743c')
     @testtools.skipUnless(CONF.compute_feature_enabled.shelve,
diff --git a/tempest/scenario/test_snapshot_pattern.py b/tempest/scenario/test_snapshot_pattern.py
index b5e5da8..79b809f 100644
--- a/tempest/scenario/test_snapshot_pattern.py
+++ b/tempest/scenario/test_snapshot_pattern.py
@@ -47,16 +47,6 @@
     def _add_keypair(self):
         self.keypair = self.create_keypair()
 
-    def _write_timestamp(self, server_or_ip):
-        ssh_client = self.get_remote_client(server_or_ip)
-        ssh_client.exec_command('date > /tmp/timestamp; sync')
-        self.timestamp = ssh_client.exec_command('cat /tmp/timestamp')
-
-    def _check_timestamp(self, server_or_ip):
-        ssh_client = self.get_remote_client(server_or_ip)
-        got_timestamp = ssh_client.exec_command('cat /tmp/timestamp')
-        self.assertEqual(self.timestamp, got_timestamp)
-
     @test.idempotent_id('608e604b-1d63-4a82-8e3e-91bc665c90b4')
     @testtools.skipUnless(CONF.compute_feature_enabled.snapshot,
                           'Snapshotting is not available.')
@@ -70,9 +60,9 @@
         server = self._boot_image(CONF.compute.image_ref)
         if CONF.compute.use_floatingip_for_ssh:
             fip_for_server = self.create_floating_ip(server)
-            self._write_timestamp(fip_for_server['ip'])
+            timestamp = self.create_timestamp(fip_for_server['ip'])
         else:
-            self._write_timestamp(server)
+            timestamp = self.create_timestamp(server)
 
         # snapshot the instance
         snapshot_image = self.create_server_snapshot(server=server)
@@ -83,6 +73,7 @@
         # check the existence of the timestamp file in the second instance
         if CONF.compute.use_floatingip_for_ssh:
             fip_for_snapshot = self.create_floating_ip(server_from_snapshot)
-            self._check_timestamp(fip_for_snapshot['ip'])
+            timestamp2 = self.get_timestamp(fip_for_snapshot['ip'])
         else:
-            self._check_timestamp(server_from_snapshot)
+            timestamp2 = self.get_timestamp(server_from_snapshot)
+        self.assertEqual(timestamp, timestamp2)
diff --git a/tempest/scenario/test_stamp_pattern.py b/tempest/scenario/test_stamp_pattern.py
index 91e4657..b9d5fcc 100644
--- a/tempest/scenario/test_stamp_pattern.py
+++ b/tempest/scenario/test_stamp_pattern.py
@@ -127,23 +127,6 @@
                                             CONF.compute.build_interval):
             raise exceptions.TimeoutException
 
-    def _create_timestamp(self, server_or_ip):
-        ssh_client = self._ssh_to_server(server_or_ip)
-        ssh_client.exec_command('sudo /usr/sbin/mkfs.ext4 /dev/%s'
-                                % CONF.compute.volume_device_name)
-        ssh_client.exec_command('sudo mount /dev/%s /mnt'
-                                % CONF.compute.volume_device_name)
-        ssh_client.exec_command('sudo sh -c "date > /mnt/timestamp;sync"')
-        self.timestamp = ssh_client.exec_command('sudo cat /mnt/timestamp')
-        ssh_client.exec_command('sudo umount /mnt')
-
-    def _check_timestamp(self, server_or_ip):
-        ssh_client = self._ssh_to_server(server_or_ip)
-        ssh_client.exec_command('sudo mount /dev/%s /mnt'
-                                % CONF.compute.volume_device_name)
-        got_timestamp = ssh_client.exec_command('sudo cat /mnt/timestamp')
-        self.assertEqual(self.timestamp, got_timestamp)
-
     @decorators.skip_because(bug="1205344")
     @test.idempotent_id('10fd234a-515c-41e5-b092-8323060598c5')
     @testtools.skipUnless(CONF.compute_feature_enabled.snapshot,
@@ -167,7 +150,8 @@
 
         self._attach_volume(server, volume)
         self._wait_for_volume_available_on_the_system(ip_for_server)
-        self._create_timestamp(ip_for_server)
+        timestamp = self.create_timestamp(ip_for_server,
+                                          CONF.compute.volume_device_name)
         self._detach_volume(server, volume)
 
         # snapshot the volume
@@ -196,4 +180,6 @@
         self._wait_for_volume_available_on_the_system(ip_for_snapshot)
 
         # check the existence of the timestamp file in the volume2
-        self._check_timestamp(ip_for_snapshot)
+        timestamp2 = self.get_timestamp(ip_for_snapshot,
+                                        CONF.compute.volume_device_name)
+        self.assertEqual(timestamp, timestamp2)
diff --git a/tempest/services/identity/v2/json/identity_client.py b/tempest/services/identity/v2/json/identity_client.py
index cf4c546..f37bc08 100644
--- a/tempest/services/identity/v2/json/identity_client.py
+++ b/tempest/services/identity/v2/json/identity_client.py
@@ -327,7 +327,8 @@
         patch_body = json.dumps({'user': patch_body})
         resp, body = self.patch('OS-KSCRUD/users/%s' % user_id, patch_body)
         self.expected_success(200, resp.status)
-        return service_client.ResponseBody(resp, self._parse_resp(body))
+        body = json.loads(body)
+        return service_client.ResponseBody(resp, body)
 
     def list_extensions(self):
         """List all the extensions."""
@@ -360,4 +361,5 @@
         resp, body = self.get('/users/%s/credentials/OS-EC2/%s' %
                               (user_id, access))
         self.expected_success(200, resp.status)
-        return service_client.ResponseBody(resp, self._parse_resp(body))
+        body = json.loads(body)
+        return service_client.ResponseBody(resp, body)