Merge "Refactor volume_boot_pattern test"

This commit is contained in:
Jenkins 2015-11-06 01:22:15 +00:00 committed by Gerrit Code Review
commit 113fc9fb26

View File

@ -95,32 +95,17 @@ class TestVolumeBootPattern(manager.ScenarioTest):
vol_name = data_utils.rand_name('volume')
return self.create_volume(name=vol_name, snapshot_id=snap_id)
def _ssh_to_server(self, server, keypair):
def _get_server_ip(self, server):
if CONF.compute.use_floatingip_for_ssh:
ip = self.create_floating_ip(server)['ip']
else:
ip = server
return self.get_remote_client(ip, private_key=keypair['private_key'],
log_console_of_servers=[server])
def _get_content(self, ssh_client):
return ssh_client.exec_command('cat /tmp/text')
def _write_text(self, ssh_client):
text = data_utils.rand_name('text')
ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text))
return self._get_content(ssh_client)
return ip
def _delete_server(self, server):
self.servers_client.delete_server(server['id'])
waiters.wait_for_server_termination(self.servers_client, server['id'])
def _check_content_of_written_file(self, ssh_client, expected):
actual = self._get_content(ssh_client)
self.assertEqual(expected, actual)
@test.idempotent_id('557cd2c2-4eb8-4dce-98be-f86765ff311b')
@test.attr(type='smoke')
@test.services('compute', 'volume', 'image')
@ -134,9 +119,9 @@ class TestVolumeBootPattern(manager.ScenarioTest):
keypair, security_group)
# write content to volume on instance
ssh_client_for_instance_1st = self._ssh_to_server(instance_1st,
keypair)
text = self._write_text(ssh_client_for_instance_1st)
ip_instance_1st = self._get_server_ip(instance_1st)
timestamp = self.create_timestamp(ip_instance_1st,
private_key=keypair['private_key'])
# delete instance
self._delete_server(instance_1st)
@ -146,9 +131,10 @@ class TestVolumeBootPattern(manager.ScenarioTest):
keypair, security_group)
# check the content of written file
ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd,
keypair)
self._check_content_of_written_file(ssh_client_for_instance_2nd, text)
ip_instance_2nd = self._get_server_ip(instance_2nd)
timestamp2 = self.get_timestamp(ip_instance_2nd,
private_key=keypair['private_key'])
self.assertEqual(timestamp, timestamp2)
# snapshot a volume
snapshot = self._create_snapshot_from_volume(volume_origin['id'])
@ -160,8 +146,10 @@ class TestVolumeBootPattern(manager.ScenarioTest):
keypair, security_group))
# check the content of written file
ssh_client = self._ssh_to_server(instance_from_snapshot, keypair)
self._check_content_of_written_file(ssh_client, text)
ip_instance_from_snapshot = self._get_server_ip(instance_from_snapshot)
timestamp3 = self.get_timestamp(ip_instance_from_snapshot,
private_key=keypair['private_key'])
self.assertEqual(timestamp, timestamp3)
@test.idempotent_id('36c34c67-7b54-4b59-b188-02a2f458a63b')
@test.services('compute', 'volume', 'image')