test_stamp_pattern: cleanup class scope variable usage
This removes the class variables for keypair and security group so we don't rely on tight coupling between method calls. Change-Id: I24149494a42c3c2988c1f6b9ef9b8541ed65dc06 Related-Bug: #1482299
This commit is contained in:
parent
fda037385c
commit
fd5657dedd
|
@ -558,8 +558,10 @@ class ScenarioTest(tempest.test.BaseTestCase):
|
|||
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)
|
||||
def create_timestamp(self, server_or_ip, dev_name=None, mount_path='/mnt',
|
||||
private_key=None):
|
||||
ssh_client = self.get_remote_client(server_or_ip,
|
||||
private_key=private_key)
|
||||
if dev_name is not None:
|
||||
ssh_client.make_fs(dev_name)
|
||||
ssh_client.mount(dev_name, mount_path)
|
||||
|
@ -571,8 +573,10 @@ class ScenarioTest(tempest.test.BaseTestCase):
|
|||
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)
|
||||
def get_timestamp(self, server_or_ip, dev_name=None, mount_path='/mnt',
|
||||
private_key=None):
|
||||
ssh_client = self.get_remote_client(server_or_ip,
|
||||
private_key=private_key)
|
||||
if dev_name is not None:
|
||||
ssh_client.mount(dev_name, mount_path)
|
||||
timestamp = ssh_client.exec_command('sudo cat %s/timestamp'
|
||||
|
|
|
@ -63,20 +63,17 @@ class TestStampPattern(manager.ScenarioTest):
|
|||
self.snapshots_client.wait_for_snapshot_status(volume_snapshot['id'],
|
||||
status)
|
||||
|
||||
def _boot_image(self, image_id):
|
||||
security_groups = [{'name': self.security_group['name']}]
|
||||
def _boot_image(self, image_id, keypair, security_group):
|
||||
security_groups = [{'name': security_group['name']}]
|
||||
create_kwargs = {
|
||||
'key_name': self.keypair['name'],
|
||||
'key_name': keypair['name'],
|
||||
'security_groups': security_groups
|
||||
}
|
||||
return self.create_server(image=image_id, create_kwargs=create_kwargs)
|
||||
|
||||
def _add_keypair(self):
|
||||
self.keypair = self.create_keypair()
|
||||
|
||||
def _create_volume_snapshot(self, volume):
|
||||
snapshot_name = data_utils.rand_name('scenario-snapshot')
|
||||
_, snapshot = self.snapshots_client.create_snapshot(
|
||||
snapshot = self.snapshots_client.create_snapshot(
|
||||
volume['id'], display_name=snapshot_name)['snapshot']
|
||||
|
||||
def cleaner():
|
||||
|
@ -111,8 +108,9 @@ class TestStampPattern(manager.ScenarioTest):
|
|||
self.servers_client.detach_volume(server['id'], volume['id'])
|
||||
self._wait_for_volume_status(volume, 'available')
|
||||
|
||||
def _wait_for_volume_available_on_the_system(self, server_or_ip):
|
||||
ssh = self.get_remote_client(server_or_ip)
|
||||
def _wait_for_volume_available_on_the_system(self, server_or_ip,
|
||||
private_key):
|
||||
ssh = self.get_remote_client(server_or_ip, private_key=private_key)
|
||||
|
||||
def _func():
|
||||
part = ssh.get_partitions()
|
||||
|
@ -131,12 +129,13 @@ class TestStampPattern(manager.ScenarioTest):
|
|||
@tempest.test.services('compute', 'network', 'volume', 'image')
|
||||
def test_stamp_pattern(self):
|
||||
# prepare for booting an instance
|
||||
self._add_keypair()
|
||||
self.security_group = self._create_security_group()
|
||||
keypair = self.create_keypair()
|
||||
security_group = self._create_security_group()
|
||||
|
||||
# boot an instance and create a timestamp file in it
|
||||
volume = self._create_volume()
|
||||
server = self._boot_image(CONF.compute.image_ref)
|
||||
server = self._boot_image(CONF.compute.image_ref, keypair,
|
||||
security_group)
|
||||
|
||||
# create and add floating IP to server1
|
||||
if CONF.compute.use_floatingip_for_ssh:
|
||||
|
@ -146,9 +145,11 @@ class TestStampPattern(manager.ScenarioTest):
|
|||
ip_for_server = server
|
||||
|
||||
self._attach_volume(server, volume)
|
||||
self._wait_for_volume_available_on_the_system(ip_for_server)
|
||||
self._wait_for_volume_available_on_the_system(ip_for_server,
|
||||
keypair['private_key'])
|
||||
timestamp = self.create_timestamp(ip_for_server,
|
||||
CONF.compute.volume_device_name)
|
||||
CONF.compute.volume_device_name,
|
||||
private_key=keypair['private_key'])
|
||||
self._detach_volume(server, volume)
|
||||
|
||||
# snapshot the volume
|
||||
|
@ -162,7 +163,8 @@ class TestStampPattern(manager.ScenarioTest):
|
|||
snapshot_id=volume_snapshot['id'])
|
||||
|
||||
# boot second instance from the snapshot(instance2)
|
||||
server_from_snapshot = self._boot_image(snapshot_image['id'])
|
||||
server_from_snapshot = self._boot_image(snapshot_image['id'],
|
||||
keypair, security_group)
|
||||
|
||||
# create and add floating IP to server_from_snapshot
|
||||
if CONF.compute.use_floatingip_for_ssh:
|
||||
|
@ -174,9 +176,11 @@ class TestStampPattern(manager.ScenarioTest):
|
|||
|
||||
# attach volume2 to instance2
|
||||
self._attach_volume(server_from_snapshot, volume_from_snapshot)
|
||||
self._wait_for_volume_available_on_the_system(ip_for_snapshot)
|
||||
self._wait_for_volume_available_on_the_system(ip_for_snapshot,
|
||||
keypair['private_key'])
|
||||
|
||||
# check the existence of the timestamp file in the volume2
|
||||
timestamp2 = self.get_timestamp(ip_for_snapshot,
|
||||
CONF.compute.volume_device_name)
|
||||
CONF.compute.volume_device_name,
|
||||
private_key=keypair['private_key'])
|
||||
self.assertEqual(timestamp, timestamp2)
|
||||
|
|
Loading…
Reference in New Issue