コード例 #1
0
ファイル: test_validate.py プロジェクト: zzxwill/heat
 def setUp(self):
     super(validateTest, self).setUp()
     resources.initialise()
     self.fc = fakes_nova.FakeClient()
     self.gc = fakes_nova.FakeClient()
     resources.initialise()
     self.ctx = utils.dummy_context()
     self.patch('heat.engine.service.warnings')
コード例 #2
0
 def setUp(self):
     super(PoolMemberTest, self).setUp()
     self.fc = fakes_nova.FakeClient()
     self.m.StubOutWithMock(neutronclient.Client, 'create_member')
     self.m.StubOutWithMock(neutronclient.Client, 'delete_member')
     self.m.StubOutWithMock(neutronclient.Client, 'update_member')
     self.m.StubOutWithMock(neutronclient.Client, 'show_member')
コード例 #3
0
ファイル: test_scaling_group.py プロジェクト: srz01/heat
 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()
コード例 #4
0
    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))
コード例 #5
0
    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,
                         'get_image_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)
コード例 #6
0
ファイル: test_scaling_group.py プロジェクト: zzxwill/heat
 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()
     cfg.CONF.set_default('heat_waitcondition_server_url',
                          'http://127.0.0.1:8000/v1/waitcondition')
コード例 #7
0
 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))
コード例 #8
0
def clean_up_stack(stack, delete_res=True):
    if delete_res:
        m = mox.Mox()
        fc = fakes_nova.FakeClient()
        m.StubOutWithMock(instances.Instance, 'nova')
        instances.Instance.nova().MultipleTimes().AndReturn(fc)
        m.StubOutWithMock(fc.client, 'get_servers_9999')
        get = fc.client.get_servers_9999
        get().AndRaise(fakes_nova.fake_exception())
        m.ReplayAll()
    stack.delete()
    if delete_res:
        m.UnsetStubs()
コード例 #9
0
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()
コード例 #10
0
    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)
コード例 #11
0
 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
コード例 #12
0
 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')
コード例 #13
0
    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, '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')
コード例 #14
0
    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)
コード例 #15
0
    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)
コード例 #16
0
def setup_mocks(mocks, stack, mock_image_constraint=True,
                mock_keystone=True):
    fc = fakes_nova.FakeClient()
    mocks.StubOutWithMock(instances.Instance, 'nova')
    instances.Instance.nova().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.t['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,
        instance.t['Properties']['UserData'],
        '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
コード例 #17
0
 def setUp(self):
     super(nokeyTest, self).setUp()
     self.fc = fakes_nova.FakeClient()
コード例 #18
0
 def setUp(self):
     super(ServerTagsTest, self).setUp()
     self.fc = fakes_nova.FakeClient()
コード例 #19
0
 def setUp(self):
     super(instancesTest, self).setUp()
     self.fc = fakes_nova.FakeClient()
コード例 #20
0
ファイル: test_scaling_group.py プロジェクト: srz01/heat
 def setUp(self):
     super(RollingUpdatePolicyDiffTest, self).setUp()
     self.fc = fakes_nova.FakeClient()
     self.stub_keystoneclient(username='******')
コード例 #21
0
ファイル: test_loadbalancer.py プロジェクト: zzxwill/heat
 def setUp(self):
     super(LoadBalancerTest, self).setUp()
     self.fc = fakes_nova.FakeClient()
     cfg.CONF.set_default('heat_waitcondition_server_url',
                          'http://server.test:8000/v1/waitcondition')
コード例 #22
0
ファイル: test_scaling_group.py プロジェクト: zzxwill/heat
 def setUp(self):
     super(RollingUpdatePolicyDiffTest, self).setUp()
     self.fc = fakes_nova.FakeClient()
     self.stub_keystoneclient(username='******')
     cfg.CONF.set_default('heat_waitcondition_server_url',
                          'http://127.0.0.1:8000/v1/waitcondition')
コード例 #23
0
ファイル: test_loadbalancer.py プロジェクト: srz01/heat
 def setUp(self):
     super(LoadBalancerTest, self).setUp()
     self.fc = fakes_nova.FakeClient()
コード例 #24
0
 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(self.fc.servers, 'get')
コード例 #25
0
 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')
コード例 #26
0
 def setUp(self):
     super(InstanceGroupTest, self).setUp()
     self.fc = fakes_nova.FakeClient()