def test_start_instance_fail_to_start(self): bs = openstack.OpenStackLatentBuildSlave('bot', 'pass', **self.bs_image_args) bs._poll_resolution = 0 self.patch(novaclient.Servers, 'fail_to_start', True) self.assertRaises(interfaces.LatentBuildSlaveFailedToSubstantiate, bs._start_instance)
def test_stop_instance_missing(self): bs = openstack.OpenStackLatentBuildSlave('bot', 'pass', **self.bs_image_args) instance = mock.Mock() instance.id = 'uuid' bs.instance = instance # TODO: Check log for instance not found. bs.stop_instance()
def test_start_instance_success(self): bs = openstack.OpenStackLatentBuildSlave('bot', 'pass', **self.bs_image_args) bs._poll_resolution = 0 uuid, image_uuid, time_waiting = bs._start_instance() self.assertTrue(uuid) self.assertEqual(image_uuid, 'image-uuid') self.assertTrue(time_waiting)
def test_stop_instance_not_set(self): """ Test stopping the instance but with no instance to stop. """ bs = openstack.OpenStackLatentBuildSlave('bot', 'pass', **self.bs_image_args) bs.instance = None stopped = yield bs.stop_instance() self.assertEqual(stopped, None)
def test_getImage_string(self): bs = openstack.OpenStackLatentBuildSlave('bot', 'pass', flavor=1, image='image-uuid', os_username='******', os_password='******', os_tenant_name='tenant', os_auth_url='auth') self.assertEqual('image-uuid', bs._getImage(None))
def test_stop_instance_notfast(self): bs = openstack.OpenStackLatentBuildSlave('bot', 'pass', **self.bs_image_args) # Make instance immediately active. self.patch(novaclient.Servers, 'gets_until_active', 0) s = novaclient.Servers() bs.instance = inst = s.create() self.assertIn(inst.id, s.instances) bs.stop_instance(fast=False) self.assertNotIn(inst.id, s.instances)
def test_start_instance_check_meta(self): meta_arg = {'some_key': 'some-value'} bs = openstack.OpenStackLatentBuildSlave('bot', 'pass', meta=meta_arg, **self.bs_image_args) bs._poll_resolution = 0 uuid, image_uuid, time_waiting = bs._start_instance() self.assertIn('meta', bs.instance.boot_kwargs) self.assertIdentical(bs.instance.boot_kwargs['meta'], meta_arg)
def test_start_instance_already_exists(self): bs = openstack.OpenStackLatentBuildSlave('bot', 'pass', flavor=1, image='image-uuid', os_username='******', os_password='******', os_tenant_name='tenant', os_auth_url='auth') bs.instance = mock.Mock() self.assertRaises(ValueError, bs.start_instance, None)
def test_getImage_callable(self): def image_callable(images): return images[0] bs = openstack.OpenStackLatentBuildSlave('bot', 'pass', flavor=1, image=image_callable, **self.os_auth) os_client = novaclient.Client('user', 'pass', 'tenant', 'auth') os_client.images.images = ['uuid1', 'uuid2', 'uuid2'] self.assertEqual('uuid1', bs._getImage(os_client, image_callable))
def test_constructor_minimal(self): bs = openstack.OpenStackLatentBuildSlave('bot', 'pass', **self.bs_image_args) self.assertEqual(bs.slavename, 'bot') self.assertEqual(bs.password, 'pass') self.assertEqual(bs.flavor, 1) self.assertEqual(bs.image, 'image-uuid') self.assertEqual(bs.block_devices, None) self.assertEqual(bs.os_username, 'user') self.assertEqual(bs.os_password, 'pass') self.assertEqual(bs.os_tenant_name, 'tenant') self.assertEqual(bs.os_auth_url, 'auth')
def test_stop_instance_unknown(self): bs = openstack.OpenStackLatentBuildSlave('bot', 'pass', **self.bs_image_args) # Make instance immediately active. self.patch(novaclient.Servers, 'gets_until_active', 0) s = novaclient.Servers() bs.instance = inst = s.create() # Set status to DELETED. Instance should not be deleted when shutting # down as it already is. inst.status = novaclient.DELETED self.assertIn(inst.id, s.instances) bs.stop_instance() self.assertIn(inst.id, s.instances)
def test_start_instance_fail_to_find(self): bs = openstack.OpenStackLatentBuildSlave('bot', 'pass', flavor=1, image='image-uuid', os_username='******', os_password='******', os_tenant_name='tenant', os_auth_url='auth') bs._poll_resolution = 0 self.patch(novaclient.Servers, 'fail_to_get', True) self.assertRaises(interfaces.LatentBuildSlaveFailedToSubstantiate, bs._start_instance)
def test_start_instance_success(self): bs = openstack.OpenStackLatentBuildSlave('bot', 'pass', flavor=1, image='image-uuid', os_username='******', os_password='******', os_tenant_name='tenant', os_auth_url='auth') bs._poll_resolution = 0 uuid, image_uuid, time_waiting = bs._start_instance() self.assertTrue(uuid) self.assertEqual(image_uuid, 'image-uuid') self.assertTrue(time_waiting)
def test_start_instance_check_meta(self): meta_arg = {'some_key': 'some-value'} bs = openstack.OpenStackLatentBuildSlave('bot', 'pass', flavor=1, image='image-uuid', os_username='******', os_password='******', os_tenant_name='tenant', os_auth_url='auth', meta=meta_arg) bs._poll_resolution = 0 uuid, image_uuid, time_waiting = bs._start_instance() self.assertIn('meta', bs.instance.boot_kwargs) self.assertIdentical(bs.instance.boot_kwargs['meta'], meta_arg)
def test_constructor_minimal(self): bs = openstack.OpenStackLatentBuildSlave('bot', 'pass', flavor=1, image='image', os_username='******', os_password='******', os_tenant_name='tenant', os_auth_url='auth') self.assertEqual(bs.slavename, 'bot') self.assertEqual(bs.password, 'pass') self.assertEqual(bs.flavor, 1) self.assertEqual(bs.image, 'image') self.assertEqual(bs.os_username, 'user') self.assertEqual(bs.os_password, 'pass') self.assertEqual(bs.os_tenant_name, 'tenant') self.assertEqual(bs.os_auth_url, 'auth')
def test_constructor_block_devices_default(self): block_devices = [{'uuid': 'uuid', 'volume_size': 10}] bs = openstack.OpenStackLatentBuildSlave('bot', 'pass', flavor=1, block_devices=block_devices, **self.os_auth) self.assertEqual(bs.image, None) self.assertEqual(len(bs.block_devices), 1) self.assertEqual(bs.block_devices, [{ 'boot_index': 0, 'delete_on_termination': True, 'destination_type': 'volume', 'device_name': 'vda', 'source_type': 'image', 'volume_size': 10, 'uuid': 'uuid' }])
def test_getImage_string(self): bs = openstack.OpenStackLatentBuildSlave('bot', 'pass', **self.bs_image_args) self.assertEqual('image-uuid', bs._getImage(None, bs.image))
def test_start_instance_already_exists(self): bs = openstack.OpenStackLatentBuildSlave('bot', 'pass', **self.bs_image_args) bs.instance = mock.Mock() self.assertRaises(ValueError, bs.start_instance, None)