Merge pull request #429 from openstack-charmers/nova-use-common-launch-instance-helper
Nova use common launch instance helper
This commit is contained in:
@@ -38,31 +38,34 @@ class BaseGuestCreateTest(unittest.TestCase):
|
||||
zaza.openstack.configure.guest.launch_instance(instance_key)
|
||||
|
||||
|
||||
class CirrosGuestCreateTest(BaseGuestCreateTest):
|
||||
class CirrosGuestCreateTest(test_utils.OpenStackBaseTest):
|
||||
"""Tests to launch a cirros image."""
|
||||
|
||||
def test_launch_small_instance(self):
|
||||
"""Launch a cirros instance and test connectivity."""
|
||||
zaza.openstack.configure.guest.launch_instance(
|
||||
glance_setup.CIRROS_IMAGE_NAME)
|
||||
self.RESOURCE_PREFIX = 'zaza-nova'
|
||||
self.launch_guest(
|
||||
'cirros', instance_key=glance_setup.CIRROS_IMAGE_NAME)
|
||||
|
||||
|
||||
class LTSGuestCreateTest(BaseGuestCreateTest):
|
||||
class LTSGuestCreateTest(test_utils.OpenStackBaseTest):
|
||||
"""Tests to launch a LTS image."""
|
||||
|
||||
def test_launch_small_instance(self):
|
||||
"""Launch a Bionic instance and test connectivity."""
|
||||
zaza.openstack.configure.guest.launch_instance(
|
||||
glance_setup.LTS_IMAGE_NAME)
|
||||
self.RESOURCE_PREFIX = 'zaza-nova'
|
||||
self.launch_guest(
|
||||
'ubuntu', instance_key=glance_setup.LTS_IMAGE_NAME)
|
||||
|
||||
|
||||
class LTSGuestCreateVolumeBackedTest(BaseGuestCreateTest):
|
||||
class LTSGuestCreateVolumeBackedTest(test_utils.OpenStackBaseTest):
|
||||
"""Tests to launch a LTS image."""
|
||||
|
||||
def test_launch_small_instance(self):
|
||||
"""Launch a Bionic instance and test connectivity."""
|
||||
zaza.openstack.configure.guest.launch_instance(
|
||||
glance_setup.LTS_IMAGE_NAME,
|
||||
self.RESOURCE_PREFIX = 'zaza-nova'
|
||||
self.launch_guest(
|
||||
'volume-backed-ubuntu', instance_key=glance_setup.LTS_IMAGE_NAME,
|
||||
use_boot_volume=True)
|
||||
|
||||
|
||||
|
||||
@@ -526,7 +526,8 @@ class OpenStackBaseTest(BaseCharmTest):
|
||||
# Test did not define self.RESOURCE_PREFIX, ignore.
|
||||
pass
|
||||
|
||||
def launch_guest(self, guest_name, userdata=None):
|
||||
def launch_guest(self, guest_name, userdata=None, use_boot_volume=False,
|
||||
instance_key=None):
|
||||
"""Launch two guests to use in tests.
|
||||
|
||||
Note that it is up to the caller to have set the RESOURCE_PREFIX class
|
||||
@@ -539,9 +540,14 @@ class OpenStackBaseTest(BaseCharmTest):
|
||||
:type guest_name: str
|
||||
:param userdata: Userdata to attach to instance
|
||||
:type userdata: Optional[str]
|
||||
:param use_boot_volume: Whether to boot guest from a shared volume.
|
||||
:type use_boot_volume: boolean
|
||||
:param instance_key: Key to collect associated config data with.
|
||||
:type instance_key: Optional[str]
|
||||
:returns: Nova instance objects
|
||||
:rtype: Server
|
||||
"""
|
||||
instance_key = instance_key or glance_setup.LTS_IMAGE_NAME
|
||||
instance_name = '{}-{}'.format(self.RESOURCE_PREFIX, guest_name)
|
||||
|
||||
instance = self.retrieve_guest(instance_name)
|
||||
@@ -554,10 +560,16 @@ class OpenStackBaseTest(BaseCharmTest):
|
||||
instance.id,
|
||||
msg="server")
|
||||
|
||||
return configure_guest.launch_instance(
|
||||
glance_setup.LTS_IMAGE_NAME,
|
||||
vm_name=instance_name,
|
||||
userdata=userdata)
|
||||
for attempt in tenacity.Retrying(
|
||||
stop=tenacity.stop_after_attempt(3),
|
||||
wait=tenacity.wait_exponential(
|
||||
multiplier=1, min=2, max=10)):
|
||||
with attempt:
|
||||
return configure_guest.launch_instance(
|
||||
instance_key,
|
||||
vm_name=instance_name,
|
||||
use_boot_volume=use_boot_volume,
|
||||
userdata=userdata)
|
||||
|
||||
def launch_guests(self, userdata=None):
|
||||
"""Launch two guests to use in tests.
|
||||
@@ -572,15 +584,10 @@ class OpenStackBaseTest(BaseCharmTest):
|
||||
"""
|
||||
launched_instances = []
|
||||
for guest_number in range(1, 2+1):
|
||||
for attempt in tenacity.Retrying(
|
||||
stop=tenacity.stop_after_attempt(3),
|
||||
wait=tenacity.wait_exponential(
|
||||
multiplier=1, min=2, max=10)):
|
||||
with attempt:
|
||||
launched_instances.append(
|
||||
self.launch_guest(
|
||||
guest_name='ins-{}'.format(guest_number),
|
||||
userdata=userdata))
|
||||
launched_instances.append(
|
||||
self.launch_guest(
|
||||
guest_name='ins-{}'.format(guest_number),
|
||||
userdata=userdata))
|
||||
return launched_instances
|
||||
|
||||
def retrieve_guest(self, guest_name):
|
||||
|
||||
Reference in New Issue
Block a user