def __init__(self, yaml_file, files, yml_data): resources.initialise() self.fc = fakes_nova.FakeClient() self.gc = fakes_nova.FakeClient() resources.initialise() self.ctx = utils.dummy_context() self.mock_isa = mock.patch( "heat.engine.resource.Resource.is_service_available", return_value=(True, None), ) self.mock_is_service_available = self.mock_isa.start() self.engine = service.EngineService("a", "t") self.yaml_file = yaml_file self.files = files self.yml_data = yml_data
def test_validate(self): client = fakes_nova.FakeClient() self.stub_keystoneclient() self.patchobject(nova.NovaClientPlugin, '_create', return_value=client) client.networks = mock.Mock() network = collections.namedtuple("Network", ['id', 'label']) network.id = '7f47ff06-0353-4013-b814-123b70b1b27d' network.label = 'foo' client.networks.get.return_value = network constraint = nova.NetworkConstraint() ctx = utils.dummy_context() self.assertTrue(constraint.validate(network.id, ctx)) client.networks.get.side_effect = nova_exceptions.NotFound('') client.networks.find.return_value = network self.assertTrue(constraint.validate(network.id, ctx)) client.networks.find.side_effect = nova_exceptions.NotFound('') self.assertFalse(constraint.validate(network.id, ctx)) client.networks.find.side_effect = nova_exceptions.NoUniqueMatch() self.assertFalse(constraint.validate(network.id, ctx)) network.id = 'nonuuid' client.networks.find.return_value = network client.networks.find.side_effect = None self.assertTrue(constraint.validate(network.id, ctx))
def test_stack_validate(self): stack_name = 'stack_create_test_validate' stk = tools.get_stack(stack_name, self.ctx) fc = fakes_nova.FakeClient() self.patchobject(nova.NovaClientPlugin, '_create', return_value=fc) self.patchobject(glance.GlanceClientPlugin, 'find_image_by_name_or_id', return_value=744) resource = stk['WebServer'] resource.properties = properties.Properties( resource.properties_schema, { 'ImageId': 'CentOS 5.2', 'KeyName': 'test', 'InstanceType': 'm1.large' }, context=self.ctx) stk.validate() resource.properties = properties.Properties( resource.properties_schema, { 'KeyName': 'test', 'InstanceType': 'm1.large' }, context=self.ctx) self.assertRaises(exception.StackValidationFailed, stk.validate)
def setUp(self): super(AllocTest, self).setUp() self.fc = fakes_nova.FakeClient() self.m.StubOutWithMock(self.fc.servers, 'get') self.m.StubOutWithMock(nova.NovaClientPlugin, '_create') self.m.StubOutWithMock(parser.Stack, 'resource_by_refid') self.m.StubOutWithMock(neutronclient.Client, 'create_floatingip') self.m.StubOutWithMock(neutronclient.Client, 'show_floatingip') self.m.StubOutWithMock(neutronclient.Client, 'update_floatingip') self.m.StubOutWithMock(neutronclient.Client, 'list_floatingips') self.m.StubOutWithMock(neutronclient.Client, 'delete_floatingip') self.m.StubOutWithMock(neutronclient.Client, 'add_gateway_router') self.m.StubOutWithMock(neutronclient.Client, 'list_networks') self.m.StubOutWithMock(neutronclient.Client, 'list_ports') self.m.StubOutWithMock(neutronclient.Client, 'show_network') self.m.StubOutWithMock(neutronclient.Client, 'list_routers') self.m.StubOutWithMock(neutronclient.Client, 'remove_gateway_router')
def setup_mocks_with_mock(testcase, stack, mock_image_constraint=True, mock_keystone=True): fc = fakes_nova.FakeClient() testcase.patchobject(instances.Instance, 'client', return_value=fc) testcase.patchobject(nova.NovaClientPlugin, '_create', return_value=fc) instance = stack['WebServer'] metadata = instance.metadata_get() if mock_image_constraint: setup_mock_for_image_constraint_with_mock( testcase, instance.properties['ImageId']) if mock_keystone: setup_keystone_mocks_with_mock(testcase, stack) user_data = instance.properties['UserData'] server_userdata = instance.client_plugin().build_userdata( metadata, user_data, 'ec2-user') testcase.patchobject(nova.NovaClientPlugin, 'build_userdata', return_value=server_userdata) testcase.patchobject(fc.servers, 'create') fc.servers.create.return_value = fc.servers.list()[4] return fc
def setUp(self): super(RollingUpdatePolicyTest, self).setUp() self.fc = fakes_nova.FakeClient() self.stub_keystoneclient(username='******') self.stub_ImageConstraint_validate() self.stub_FlavorConstraint_validate() self.stub_SnapshotConstraint_validate()
def setup_mocks(mocks, stack, mock_image_constraint=True, mock_keystone=True): fc = fakes_nova.FakeClient() mocks.StubOutWithMock(instances.Instance, 'client') instances.Instance.client().MultipleTimes().AndReturn(fc) mocks.StubOutWithMock(nova.NovaClientPlugin, '_create') nova.NovaClientPlugin._create().AndReturn(fc) instance = stack['WebServer'] metadata = instance.metadata_get() if mock_image_constraint: setup_mock_for_image_constraint(mocks, instance.properties['ImageId']) if mock_keystone: setup_keystone_mocks(mocks, stack) user_data = instance.properties['UserData'] server_userdata = instance.client_plugin().build_userdata( metadata, user_data, 'ec2-user') mocks.StubOutWithMock(nova.NovaClientPlugin, 'build_userdata') nova.NovaClientPlugin.build_userdata(metadata, user_data, 'ec2-user').AndReturn(server_userdata) mocks.StubOutWithMock(fc.servers, 'create') fc.servers.create(image=744, flavor=3, key_name='test', name=utils.PhysName(stack.name, 'WebServer'), security_groups=None, userdata=server_userdata, scheduler_hints=None, meta=None, nics=None, availability_zone=None, block_device_mapping=None).AndReturn( fc.servers.list()[4]) return fc
def setUp(self): super(PoolMemberTest, self).setUp() self.fc = fakes_nova.FakeClient() self.mc = mock.Mock(spec=neutronclient.Client) self.patchobject(neutronclient, 'Client', return_value=self.mc) self.patchobject(neutron.NeutronClientPlugin, 'has_extension', return_value=True)
def test_validate(self): client = fakes_nova.FakeClient() self.stub_keystoneclient() self.patchobject(nova.NovaClientPlugin, 'get_max_microversion', return_value='2.27') self.patchobject(nova.NovaClientPlugin, '_create', return_value=client) client.flavors = mock.MagicMock() flavor = collections.namedtuple("Flavor", ["id", "name"]) flavor.id = "1234" flavor.name = "foo" client.flavors.get.side_effect = [flavor, nova_exceptions.NotFound(''), nova_exceptions.NotFound('')] client.flavors.find.side_effect = [flavor, nova_exceptions.NotFound('')] constraint = nova.FlavorConstraint() ctx = utils.dummy_context() self.assertTrue(constraint.validate("1234", ctx)) self.assertTrue(constraint.validate("foo", ctx)) self.assertFalse(constraint.validate("bar", ctx)) self.assertEqual(1, nova.NovaClientPlugin._create.call_count) self.assertEqual(3, client.flavors.get.call_count) self.assertEqual(2, client.flavors.find.call_count)
def clean_up_stack(test_case, stack, delete_res=True): if delete_res: fc = fakes_nova.FakeClient() test_case.patchobject(instances.Instance, 'client', return_value=fc) test_case.patchobject(fc.servers, 'delete', side_effect=fakes_nova.fake_exception()) stack.delete()
def setUp(self): super(LoadBalancerTest, self).setUp() self.fc = fakes_nova.FakeClient() self.m.StubOutWithMock(neutronclient.Client, 'create_member') self.m.StubOutWithMock(neutronclient.Client, 'delete_member') self.m.StubOutWithMock(nova.NovaClientPlugin, '_create') self.patchobject(neutron.NeutronClientPlugin, 'has_extension', return_value=True)
def test_get_azs_with_stack(self): tmpl = template.Template(empty_template) snippet = {"Fn::GetAZs": ""} stk = stack.Stack(self.ctx, 'test_stack', template.Template(empty_template)) self.m.StubOutWithMock(nova.NovaClientPlugin, '_create') fc = fakes_nova.FakeClient() nova.NovaClientPlugin._create().AndReturn(fc) self.m.ReplayAll() self.assertEqual(["nova1"], self.resolve(snippet, tmpl, stk))
def setUp(self): # force Nova, will test Neutron below super(EIPTest, self).setUp() self.fc = fakes_nova.FakeClient() self.m.StubOutWithMock(nova.NovaClientPlugin, '_create') self.m.StubOutWithMock(neutronclient.Client, 'list_networks') self.m.StubOutWithMock(self.fc.servers, 'get') self.m.StubOutWithMock(neutronclient.Client, 'create_floatingip') self.m.StubOutWithMock(neutronclient.Client, 'show_floatingip') self.m.StubOutWithMock(neutronclient.Client, 'update_floatingip') self.m.StubOutWithMock(neutronclient.Client, 'delete_floatingip')
def clean_up_stack(stack, delete_res=True): if delete_res: m = mox.Mox() fc = fakes_nova.FakeClient() m.StubOutWithMock(instances.Instance, 'client') instances.Instance.client().MultipleTimes().AndReturn(fc) m.StubOutWithMock(fc.servers, 'delete') fc.servers.delete(mox.IgnoreArg()).AndRaise( fakes_nova.fake_exception()) m.ReplayAll() stack.delete() if delete_res: m.UnsetStubs()
def setUp(self): super(CloudServersTest, self).setUp() cfg.CONF.set_override('region_name_for_services', 'RegionOne') self.ctx = utils.dummy_context() self.fc = fakes.FakeClient() mock_nova_create = mock.Mock() self.ctx.clients.client_plugin('nova')._create = mock_nova_create mock_nova_create.return_value = self.fc # Test environment may not have pyrax client library installed and if # pyrax is not installed resource class would not be registered. # So register resource provider class explicitly for unit testing. resource._register_class("OS::Nova::Server", cloud_server.CloudServer)
def setUp(self): super(NovaFloatingIPTest, self).setUp() self.novaclient = fakes_nova.FakeClient() self.patchobject(nova.NovaClientPlugin, 'client', return_value=self.novaclient) self.mock_create_fip = self.patchobject(neutronclient.Client, 'create_floatingip') self.mock_upd_fip = self.patchobject(neutronclient.Client, 'update_floatingip') self.mock_del_fip = self.patchobject(neutronclient.Client, 'delete_floatingip') self.patchobject(neutron.NeutronClientPlugin, 'find_resourceid_by_name_or_id', return_value='eeee')
def setUp(self): # force Nova, will test Neutron below super(EIPTest, self).setUp() self.fc = fakes_nova.FakeClient() self.patchobject(nova.NovaClientPlugin, 'client', return_value=self.fc) self.mock_list_net = self.patchobject(neutronclient.Client, 'list_networks') self.mock_create_fip = self.patchobject(neutronclient.Client, 'create_floatingip') self.mock_show_fip = self.patchobject(neutronclient.Client, 'show_floatingip') self.patchobject(neutronclient.Client, 'update_floatingip') self.patchobject(neutronclient.Client, 'delete_floatingip') self.mock_list_fips = self.patchobject(neutronclient.Client, 'list_floatingips')
def setUp(self): super(VolumeTestCase, self).setUp() self.fc = fakes_nova.FakeClient() self.cinder_fc = cinderclient.Client('username', 'password') self.cinder_fc.volume_api_version = 2 self.patchobject(cinder.CinderClientPlugin, '_create', return_value=self.cinder_fc) self.patchobject(nova.NovaClientPlugin, '_create', return_value=self.fc) self.cinder_fc.volumes = mock.Mock(spec=self.cinder_fc.volumes) self.fc.volumes = mock.Mock() self.use_cinder = False self.m_backups = mock.Mock(spec=self.cinder_fc.backups) self.m_restore = mock.Mock(spec=self.cinder_fc.restores.restore) self.cinder_fc.backups = self.m_backups self.cinder_fc.restores.restore = self.m_restore
def test_validation(self): client = fakes_nova.FakeClient() self.patchobject(nova.NovaClientPlugin, '_create', return_value=client) client.keypairs = mock.MagicMock() key = collections.namedtuple("Key", ["name"]) key.name = "foo" client.keypairs.get.side_effect = [fakes_nova.fake_exception(), key] constraint = nova.KeypairConstraint() ctx = utils.dummy_context() self.assertFalse(constraint.validate("bar", ctx)) self.assertTrue(constraint.validate("foo", ctx)) self.assertTrue(constraint.validate("", ctx)) nova.NovaClientPlugin._create.assert_called_once_with() calls = [mock.call('bar'), mock.call(key.name)] client.keypairs.get.assert_has_calls(calls)
def setUp(self): super(BaseVolumeTest, self).setUp() self.fc = fakes_nova.FakeClient() self.cinder_fc = cinderclient.Client('username', 'password') self.cinder_fc.volume_api_version = 2 self.m.StubOutWithMock(cinder.CinderClientPlugin, '_create') self.m.StubOutWithMock(nova.NovaClientPlugin, '_create') self.m.StubOutWithMock(self.cinder_fc.volumes, 'create') self.m.StubOutWithMock(self.cinder_fc.volumes, 'get') self.m.StubOutWithMock(self.cinder_fc.volumes, 'delete') self.m.StubOutWithMock(self.cinder_fc.volumes, 'extend') self.m.StubOutWithMock(self.cinder_fc.volumes, 'update') self.m.StubOutWithMock(self.cinder_fc.volumes, 'update_all_metadata') self.m.StubOutWithMock(self.fc.volumes, 'create_server_volume') self.m.StubOutWithMock(self.fc.volumes, 'delete_server_volume') self.m.StubOutWithMock(self.fc.volumes, 'get_server_volume') self.use_cinder = False
def test_validate(self): client = fakes_nova.FakeClient() self.stub_keystoneclient() self.patchobject(nova.NovaClientPlugin, '_create', return_value=client) client.flavors = mock.MagicMock() flavor = collections.namedtuple("Flavor", ["id", "name"]) flavor.id = "1234" flavor.name = "foo" client.flavors.list.return_value = [flavor] constraint = nova.FlavorConstraint() ctx = utils.dummy_context() self.assertFalse(constraint.validate("bar", ctx)) self.assertTrue(constraint.validate("foo", ctx)) self.assertTrue(constraint.validate("1234", ctx)) nova.NovaClientPlugin._create.assert_called_once_with() self.assertEqual(3, client.flavors.list.call_count) self.assertEqual([(), (), ()], client.flavors.list.call_args_list)
def setUp(self): super(SecurityGroupTest, self).setUp() self.fc = fakes_nova.FakeClient() self.m.StubOutWithMock(nova.NovaClientPlugin, '_create') self.m.StubOutWithMock(nova_sgr.SecurityGroupRuleManager, 'create') self.m.StubOutWithMock(nova_sgr.SecurityGroupRuleManager, 'delete') self.m.StubOutWithMock(nova_sg.SecurityGroupManager, 'create') self.m.StubOutWithMock(nova_sg.SecurityGroupManager, 'delete') self.m.StubOutWithMock(nova_sg.SecurityGroupManager, 'get') self.m.StubOutWithMock(nova_sg.SecurityGroupManager, 'list') self.m.StubOutWithMock(nova_sg.SecurityGroupManager, 'update') self.m.StubOutWithMock(neutronclient.Client, 'create_security_group') self.m.StubOutWithMock(neutronclient.Client, 'create_security_group_rule') self.m.StubOutWithMock(neutronclient.Client, 'show_security_group') self.m.StubOutWithMock(neutronclient.Client, 'delete_security_group_rule') self.m.StubOutWithMock(neutronclient.Client, 'delete_security_group') self.m.StubOutWithMock(neutronclient.Client, 'update_security_group')
def test_nokey_create(self): stack_name = 's_nokey' t = template_format.parse(nokey_template) stack = utils.parse_stack(t, stack_name=stack_name) resource_defns = stack.t.resource_definitions(stack) instance = instances.Instance('create_instance_name', resource_defns['WebServer'], stack) # need to resolve the template functions metadata = instance.metadata_get() server_userdata = instance.client_plugin().build_userdata( metadata, instance.properties['UserData'], 'ec2-user') fc = fakes_nova.FakeClient() self.patchobject(nova.NovaClientPlugin, '_create', return_value=fc) self.patchobject(glance.GlanceClientPlugin, 'find_image_by_name_or_id', return_value=1234) self.patchobject(nova.NovaClientPlugin, 'build_userdata', return_value=server_userdata) self.patchobject(fc.servers, 'create', return_value=fc.servers.list()[1]) scheduler.TaskRunner(instance.create)() fc.servers.create.assert_called_once_with(image=1234, flavor=3, key_name=None, name=utils.PhysName( stack_name, instance.name), security_groups=None, userdata=server_userdata, scheduler_hints=None, meta=None, nics=None, availability_zone=None, block_device_mapping=None)
def setUp(self): super(SecurityGroupTest, self).setUp() self.fc = fakes_nova.FakeClient() self.m.StubOutWithMock(nova_sgr.SecurityGroupRuleManager, 'create') self.m.StubOutWithMock(nova_sgr.SecurityGroupRuleManager, 'delete') self.m.StubOutWithMock(nova_sg.SecurityGroupManager, 'create') self.m.StubOutWithMock(nova_sg.SecurityGroupManager, 'delete') self.m.StubOutWithMock(nova_sg.SecurityGroupManager, 'get') self.m.StubOutWithMock(nova_sg.SecurityGroupManager, 'list') self.m.StubOutWithMock(neutronclient.Client, 'create_security_group') self.m.StubOutWithMock(neutronclient.Client, 'create_security_group_rule') self.m.StubOutWithMock(neutronclient.Client, 'show_security_group') self.m.StubOutWithMock(neutronclient.Client, 'delete_security_group_rule') self.m.StubOutWithMock(neutronclient.Client, 'delete_security_group') self.m.StubOutWithMock(neutronclient.Client, 'update_security_group') self.patchobject(neutron.NeutronClientPlugin, 'has_extension', return_value=True)
def setUp(self): super(AllocTest, self).setUp() self.fc = fakes_nova.FakeClient() self.patchobject(nova.NovaClientPlugin, 'client', return_value=self.fc) self.mock_list_net = self.patchobject(neutronclient.Client, 'list_networks') self.mock_create_fip = self.patchobject(neutronclient.Client, 'create_floatingip') self.mock_show_fip = self.patchobject(neutronclient.Client, 'show_floatingip') self.patchobject(neutronclient.Client, 'update_floatingip') self.patchobject(neutronclient.Client, 'delete_floatingip') self.mock_list_fips = self.patchobject(neutronclient.Client, 'list_floatingips') self.patchobject(neutronclient.Client, 'add_gateway_router') self.mock_list_ports = self.patchobject(neutronclient.Client, 'list_ports') self.mock_show_net = self.patchobject(neutronclient.Client, 'show_network') self.mock_list_routers = self.patchobject(neutronclient.Client, 'list_routers') self.patchobject(neutronclient.Client, 'remove_gateway_router')
def setUp(self): super(instancesTest, self).setUp() self.fc = fakes_nova.FakeClient()
def setUp(self): super(InstanceGroupTest, self).setUp() self.fc = fakes_nova.FakeClient() self.stub_ImageConstraint_validate() self.stub_KeypairConstraint_validate() self.stub_FlavorConstraint_validate()
def setUp(self): super(LoadBalancerTest, self).setUp() self.fc = fakes_nova.FakeClient()
def setUp(self): super(RollingUpdatePolicyDiffTest, self).setUp() self.fc = fakes_nova.FakeClient() self.stub_keystoneclient(username='******')
def setUp(self): super(ServerTagsTest, self).setUp() self.fc = fakes_nova.FakeClient()