Exemple #1
0
    def setUp(self):
        """Shared implementation for tests below that create instance."""
        super(MultiCreateExtensionTestV21, self).setUp()

        self.flags(enable_instance_password=True, group='api')
        self.instance_cache_num = 0
        self.instance_cache_by_id = {}
        self.instance_cache_by_uuid = {}

        # Network API needs to be stubbed out before creating the controllers.
        fakes.stub_out_nw_api(self)

        self.controller = servers_v21.ServersController()

        def instance_get(context, instance_id):
            """Stub for compute/api create() pulling in instance after
            scheduling
            """
            return self.instance_cache_by_id[instance_id]

        def instance_update(context, uuid, values):
            instance = self.instance_cache_by_uuid[uuid]
            instance.update(values)
            return instance

        def server_update(context,
                          instance_uuid,
                          params,
                          columns_to_join=None):
            inst = self.instance_cache_by_uuid[instance_uuid]
            inst.update(params)
            return (inst, inst)

        def fake_method(*args, **kwargs):
            pass

        def project_get_networks(context, user_id):
            return dict(id='1', host='localhost')

        def create_db_entry_for_new_instance(*args, **kwargs):
            instance = args[4]
            self.instance_cache_by_uuid[instance.uuid] = instance
            return instance

        fakes.stub_out_key_pair_funcs(self)
        fake.stub_out_image_service(self)
        self.stub_out('nova.db.api.instance_add_security_group',
                      return_security_group)
        self.stub_out('nova.db.api.project_get_networks', project_get_networks)
        self.stub_out('nova.compute.api.API.create_db_entry_for_new_instance',
                      create_db_entry_for_new_instance)
        self.stub_out('nova.db.api.instance_system_metadata_update',
                      fake_method)
        self.stub_out('nova.db.api.instance_get', instance_get)
        self.stub_out('nova.db.api.instance_update', instance_update)
        self.stub_out('nova.db.api.instance_update_and_get_original',
                      server_update)
        self.stub_out('nova.network.manager.VlanManager.allocate_fixed_ip',
                      fake_method)
        self.req = fakes.HTTPRequest.blank('')
Exemple #2
0
    def test_metadata_json(self):
        fakes.stub_out_key_pair_funcs(self.stubs)
        inst = self.instance.obj_clone()
        content = [
            ('/etc/my.conf', "content of my.conf"),
            ('/root/hello', "content of /root/hello"),
        ]

        mdinst = fake_InstanceMetadata(self.stubs, inst,
            content=content)
        mdjson = mdinst.lookup("/openstack/2012-08-10/meta_data.json")
        mdjson = mdinst.lookup("/openstack/latest/meta_data.json")

        mddict = jsonutils.loads(mdjson)

        self.assertEqual(mddict['uuid'], self.instance['uuid'])
        self.assertIn('files', mddict)

        self.assertIn('public_keys', mddict)
        self.assertEqual(mddict['public_keys'][self.instance['key_name']],
            self.instance['key_data'])

        self.assertIn('launch_index', mddict)
        self.assertEqual(mddict['launch_index'], self.instance['launch_index'])

        # verify that each of the things we put in content
        # resulted in an entry in 'files', that their content
        # there is as expected, and that /content lists them.
        for (path, content) in content:
            fent = [f for f in mddict['files'] if f['path'] == path]
            self.assertEqual(1, len(fent))
            fent = fent[0]
            found = mdinst.lookup("/openstack%s" % fent['content_path'])
            self.assertEqual(found, content)
Exemple #3
0
 def test_InstanceMetadata_invoke_metadata_for_config_drive(self):
     fakes.stub_out_key_pair_funcs(self.stubs)
     inst = self.instance.obj_clone()
     inst_md = base.InstanceMetadata(inst)
     expected_paths = [
         "ec2/2009-04-04/user-data",
         "ec2/2009-04-04/meta-data.json",
         "ec2/latest/user-data",
         "ec2/latest/meta-data.json",
         "openstack/2012-08-10/meta_data.json",
         "openstack/2012-08-10/user_data",
         "openstack/2013-04-04/meta_data.json",
         "openstack/2013-04-04/user_data",
         "openstack/2013-10-17/meta_data.json",
         "openstack/2013-10-17/user_data",
         "openstack/2013-10-17/vendor_data.json",
         "openstack/2015-10-15/meta_data.json",
         "openstack/2015-10-15/user_data",
         "openstack/2015-10-15/vendor_data.json",
         "openstack/2015-10-15/network_data.json",
         "openstack/latest/meta_data.json",
         "openstack/latest/user_data",
         "openstack/latest/vendor_data.json",
         "openstack/latest/network_data.json",
     ]
     actual_paths = []
     for (path, value) in inst_md.metadata_for_config_drive():
         actual_paths.append(path)
         self.assertIsNotNone(path)
     self.assertEqual(expected_paths, actual_paths)
Exemple #4
0
    def setUp(self):
        """Shared implementation for tests below that create instance."""
        super(MultiCreateExtensionTestV21, self).setUp()

        self.flags(enable_instance_password=True, group='api')
        self.instance_cache_num = 0
        self.instance_cache_by_id = {}
        self.instance_cache_by_uuid = {}

        # Network API needs to be stubbed out before creating the controllers.
        fakes.stub_out_nw_api(self)

        ext_info = extension_info.LoadedExtensionInfo()
        self.controller = servers_v21.ServersController(
            extension_info=ext_info)

        def instance_get(context, instance_id):
            """Stub for compute/api create() pulling in instance after
            scheduling
            """
            return self.instance_cache_by_id[instance_id]

        def instance_update(context, uuid, values):
            instance = self.instance_cache_by_uuid[uuid]
            instance.update(values)
            return instance

        def server_update(context, instance_uuid, params,
                          columns_to_join=None):
            inst = self.instance_cache_by_uuid[instance_uuid]
            inst.update(params)
            return (inst, inst)

        def fake_method(*args, **kwargs):
            pass

        def project_get_networks(context, user_id):
            return dict(id='1', host='localhost')

        def create_db_entry_for_new_instance(*args, **kwargs):
            instance = args[4]
            self.instance_cache_by_uuid[instance.uuid] = instance
            return instance

        fakes.stub_out_key_pair_funcs(self)
        fake.stub_out_image_service(self)
        self.stub_out('nova.db.instance_add_security_group',
                      return_security_group)
        self.stub_out('nova.db.project_get_networks', project_get_networks)
        self.stub_out('nova.compute.api.API.create_db_entry_for_new_instance',
                      create_db_entry_for_new_instance)
        self.stub_out('nova.db.instance_system_metadata_update', fake_method)
        self.stub_out('nova.db.instance_get', instance_get)
        self.stub_out('nova.db.instance_update', instance_update)
        self.stub_out('nova.db.instance_update_and_get_original',
                      server_update)
        self.stub_out('nova.network.manager.VlanManager.allocate_fixed_ip',
                      fake_method)
        self.req = fakes.HTTPRequest.blank('')
Exemple #5
0
    def test_no_dashes_in_metadata(self):
        # top level entries in meta_data should not contain '-' in their name
        fakes.stub_out_key_pair_funcs(self.stubs)
        inst = self.instance.obj_clone()
        mdinst = fake_InstanceMetadata(self.stubs, inst)
        mdjson = jsonutils.loads(mdinst.lookup("/openstack/latest/meta_data.json"))

        self.assertEqual([], [k for k in mdjson.keys() if k.find("-") != -1])
Exemple #6
0
    def test_json_data(self):
        fakes.stub_out_key_pair_funcs(self.stubs)
        response = fake_request(self.stubs, self.mdinst, "/openstack/latest/meta_data.json")
        response_ctype = response.headers["Content-Type"]
        self.assertTrue(response_ctype.startswith("application/json"))

        response = fake_request(self.stubs, self.mdinst, "/openstack/latest/vendor_data.json")
        response_ctype = response.headers["Content-Type"]
        self.assertTrue(response_ctype.startswith("application/json"))
Exemple #7
0
    def test_extra_md(self):
        # make sure extra_md makes it through to metadata
        fakes.stub_out_key_pair_funcs(self.stubs)
        inst = self.instance.obj_clone()
        extra = {"foo": "bar", "mylist": [1, 2, 3], "mydict": {"one": 1, "two": 2}}
        mdinst = fake_InstanceMetadata(self.stubs, inst, extra_md=extra)

        mdjson = mdinst.lookup("/openstack/2012-08-10/meta_data.json")
        mddict = jsonutils.loads(mdjson)

        for key, val in six.iteritems(extra):
            self.assertEqual(mddict[key], val)
 def setUp(self):
     super(BadStateServerMetaDataTestV21, self).setUp()
     fakes.stub_out_key_pair_funcs(self.stubs)
     self.stubs.Set(nova.db, 'instance_metadata_get',
                    return_server_metadata)
     self.stubs.Set(compute_rpcapi.ComputeAPI, 'change_instance_metadata',
                    fake_change_instance_metadata)
     self.stubs.Set(nova.db, 'instance_get', self._return_server_in_build)
     self.stubs.Set(nova.db, 'instance_get_by_uuid',
                    self._return_server_in_build_by_uuid)
     self.stubs.Set(nova.db, 'instance_metadata_delete',
                    delete_server_metadata)
     self._set_up_resources()
    def setUp(self):
        super(ServerMetaDataTestV21, self).setUp()
        fakes.stub_out_key_pair_funcs(self.stubs)
        self.stubs.Set(nova.db, 'instance_get', return_server)
        self.stubs.Set(nova.db, 'instance_get_by_uuid',
                       return_server_by_uuid)

        self.stubs.Set(nova.db, 'instance_metadata_get',
                       return_server_metadata)

        self.stubs.Set(compute_rpcapi.ComputeAPI, 'change_instance_metadata',
                       fake_change_instance_metadata)
        self._set_up_resources()
Exemple #10
0
    def test_x509_keypair(self):
        # check if the x509 content is set, if the keypair type is x509.
        fakes.stub_out_key_pair_funcs(self.stubs, type="x509")
        inst = self.instance.obj_clone()
        mdinst = fake_InstanceMetadata(self.stubs, inst)

        mdjson = mdinst.lookup("/openstack/2012-08-10/meta_data.json")
        mddict = jsonutils.loads(mdjson)

        # keypair is stubbed-out, so it's public_key is 'public_key'.
        expected = {"name": self.instance["key_name"], "type": "x509", "data": "public_key"}

        self.assertEqual([expected], mddict["keys"])
 def setUp(self):
     super(BadStateServerMetaDataTestV21, self).setUp()
     fakes.stub_out_key_pair_funcs(self.stubs)
     self.stub_out('nova.db.instance_metadata_get',
                   return_server_metadata)
     self.stubs.Set(compute_rpcapi.ComputeAPI, 'change_instance_metadata',
                    fake_change_instance_metadata)
     self.stub_out('nova.db.instance_get', self._return_server_in_build)
     self.stub_out('nova.db.instance_get_by_uuid',
                   self._return_server_in_build_by_uuid)
     self.stub_out('nova.db.instance_metadata_delete',
                   delete_server_metadata)
     self._set_up_resources()
Exemple #12
0
    def test_extra_md(self):
        # make sure extra_md makes it through to metadata
        fakes.stub_out_key_pair_funcs(self.stubs)
        inst = self.instance.obj_clone()
        extra = {'foo': 'bar', 'mylist': [1, 2, 3],
                 'mydict': {"one": 1, "two": 2}}
        mdinst = fake_InstanceMetadata(self.stubs, inst, extra_md=extra)

        mdjson = mdinst.lookup("/openstack/2012-08-10/meta_data.json")
        mddict = jsonutils.loads(mdjson)

        for key, val in extra.iteritems():
            self.assertEqual(mddict[key], val)
Exemple #13
0
    def test_project_id(self):
        fakes.stub_out_key_pair_funcs(self.stubs)
        mdinst = fake_InstanceMetadata(self.stubs, self.instance)

        # verify that 2015-10-15 has the 'project_id' field
        mdjson = mdinst.lookup("/openstack/2015-10-15/meta_data.json")
        mddict = jsonutils.loads(mdjson)

        self.assertIn("project_id", mddict)
        self.assertEqual(mddict["project_id"], self.instance.project_id)

        # verify that older version do not have it
        mdjson = mdinst.lookup("/openstack/2013-10-17/meta_data.json")
        self.assertNotIn("project_id", jsonutils.loads(mdjson))
Exemple #14
0
    def test_x509_keypair(self):
        # check if the x509 content is set, if the keypair type is x509.
        fakes.stub_out_key_pair_funcs(self.stubs, type='x509')
        inst = self.instance.obj_clone()
        mdinst = fake_InstanceMetadata(self.stubs, inst)

        mdjson = mdinst.lookup("/openstack/2012-08-10/meta_data.json")
        mddict = jsonutils.loads(mdjson)

        # keypair is stubbed-out, so it's public_key is 'public_key'.
        expected = {'name': self.instance['key_name'],
                    'type': 'x509',
                    'data': 'public_key'}

        self.assertEqual([expected], mddict['keys'])
Exemple #15
0
    def test_random_seed(self):
        fakes.stub_out_key_pair_funcs(self.stubs)
        inst = self.instance.obj_clone()
        mdinst = fake_InstanceMetadata(self.stubs, inst)

        # verify that 2013-04-04 has the 'random' field
        mdjson = mdinst.lookup("/openstack/2013-04-04/meta_data.json")
        mddict = jsonutils.loads(mdjson)

        self.assertIn("random_seed", mddict)
        self.assertEqual(len(base64.b64decode(mddict["random_seed"])), 512)

        # verify that older version do not have it
        mdjson = mdinst.lookup("/openstack/2012-08-10/meta_data.json")
        self.assertNotIn("random_seed", jsonutils.loads(mdjson))
Exemple #16
0
    def test_x509_keypair(self):
        # check if the x509 content is set, if the keypair type is x509.
        fakes.stub_out_key_pair_funcs(self.stubs, type='x509')
        inst = self.instance.obj_clone()
        mdinst = fake_InstanceMetadata(self.stubs, inst)

        mdjson = mdinst.lookup("/openstack/2012-08-10/meta_data.json")
        mddict = jsonutils.loads(mdjson)

        # keypair is stubbed-out, so it's public_key is 'public_key'.
        expected = {'name': self.instance['key_name'],
                    'type': 'x509',
                    'data': 'public_key'}

        self.assertEqual([expected], mddict['keys'])
Exemple #17
0
    def test_server_rebuild(self):
        fakes.stub_out_key_pair_funcs(self)
        uuid = self._post_server()
        image = fake.get_valid_image_id()
        params = {
            'uuid': image,
            'name': 'foobar',
            'key_name': 'new-key',
            'description': 'description of foobar',
            'pass': '******',
            'hostid': '[a-f0-9]+',
            'access_ip_v4': '1.2.3.4',
            'access_ip_v6': '80fe::',
        }

        resp = self._do_post('servers/%s/action' % uuid,
                             'server-action-rebuild', params)
        subs = params.copy()
        del subs['uuid']
        self._verify_response('server-action-rebuild-resp', subs, resp, 202)
Exemple #18
0
    def test_server_rebuild(self):
        fakes.stub_out_key_pair_funcs(self)
        uuid = self._create_server()
        image = fake.get_valid_image_id()
        params = {
            'uuid': image,
            'name': 'foobar',
            'key_name': 'new-key',
            'description': 'description of foobar',
            'pass': '******',
            'hostid': '[a-f0-9]+',
            'access_ip_v4': '1.2.3.4',
            'access_ip_v6': '80fe::',
        }

        resp = self._do_post('servers/%s/action' % uuid,
                             'server-action-rebuild', params)
        subs = params.copy()
        del subs['uuid']
        self._verify_response('server-action-rebuild-resp', subs, resp, 202)
Exemple #19
0
    def test_server_rebuild(self):
        uuid = self._post_server(use_common_server_api_samples=False)
        fakes.stub_out_key_pair_funcs(self)
        image = fake.get_valid_image_id()

        params = {
            'uuid': image,
            'name': 'foobar',
            'key_name': 'new-key',
            'description': 'description of foobar',
            'pass': '******',
            'access_ip_v4': '1.2.3.4',
            'access_ip_v6': '80fe::',
        }

        resp = self._do_post('servers/%s/action' % uuid,
                             'server-action-rebuild', params)

        exp_resp = params.copy()
        del exp_resp['uuid']
        exp_resp['hostid'] = '[a-f0-9]+'

        self._verify_response('server-action-rebuild-resp',
                              exp_resp, resp, 202)
 def setUp(self):
     super(FlavorsExtraSpecsTestV21, self).setUp()
     fakes.stub_out_key_pair_funcs(self)
     self.controller = self.flavorextraspecs.FlavorExtraSpecsController()
Exemple #21
0
    def setUp(self):
        """Run before each test."""
        super(ImagesControllerTestV21, self).setUp()
        self.flags(api_servers=["http://localhost:9292"], group="glance")
        fakes.stub_out_networking(self)
        fakes.stub_out_key_pair_funcs(self)
        fakes.stub_out_compute_api_snapshot(self.stubs)
        fakes.stub_out_compute_api_backup(self.stubs)

        self.controller = self.image_controller_class()
        self.url_prefix = "http://localhost%s/images" % self.url_base
        self.bookmark_prefix = "http://localhost%s/images" % self.bookmark_base
        self.uuid = "fa95aaf5-ab3b-4cd8-88c0-2be7dd051aaf"
        self.server_uuid = "aa640691-d1a7-4a67-9d3c-d35ee6b3cc74"
        self.server_href = "http://localhost%s/servers/%s" % (self.url_base, self.server_uuid)
        self.server_bookmark = "http://localhost%s/servers/%s" % (self.bookmark_base, self.server_uuid)
        self.alternate = "%s/images/%s"

        self.expected_image_123 = {
            "image": {
                "id": "123",
                "name": "public image",
                "metadata": {"key1": "value1"},
                "updated": NOW_API_FORMAT,
                "created": NOW_API_FORMAT,
                "status": "ACTIVE",
                "minDisk": 10,
                "progress": 100,
                "minRam": 128,
                "links": [
                    {"rel": "self", "href": "%s/123" % self.url_prefix},
                    {"rel": "bookmark", "href": "%s/123" % self.bookmark_prefix},
                    {
                        "rel": "alternate",
                        "type": "application/vnd.openstack.image",
                        "href": self.alternate % (glance.generate_glance_url(), 123),
                    },
                ],
            }
        }

        self.expected_image_124 = {
            "image": {
                "id": "124",
                "name": "queued snapshot",
                "metadata": {u"instance_uuid": self.server_uuid, u"user_id": u"fake"},
                "updated": NOW_API_FORMAT,
                "created": NOW_API_FORMAT,
                "status": "SAVING",
                "progress": 25,
                "minDisk": 0,
                "minRam": 0,
                "server": {
                    "id": self.server_uuid,
                    "links": [
                        {"rel": "self", "href": self.server_href},
                        {"rel": "bookmark", "href": self.server_bookmark},
                    ],
                },
                "links": [
                    {"rel": "self", "href": "%s/124" % self.url_prefix},
                    {"rel": "bookmark", "href": "%s/124" % self.bookmark_prefix},
                    {
                        "rel": "alternate",
                        "type": "application/vnd.openstack.image",
                        "href": self.alternate % (glance.generate_glance_url(), 124),
                    },
                ],
            }
        }
Exemple #22
0
 def test_InstanceMetadata_invoke_metadata_for_config_drive(self):
     fakes.stub_out_key_pair_funcs(self.stubs)
     inst = self.instance.obj_clone()
     inst_md = base.InstanceMetadata(inst)
     for (path, value) in inst_md.metadata_for_config_drive():
         self.assertIsNotNone(path)
    def setUp(self):
        """Shared implementation for tests below that create instance."""
        super(MultiCreateExtensionTestV21, self).setUp()

        self.flags(verbose=True,
                   enable_instance_password=True)
        self.instance_cache_num = 0
        self.instance_cache_by_id = {}
        self.instance_cache_by_uuid = {}

        ext_info = extension_info.LoadedExtensionInfo()
        self.controller = servers_v21.ServersController(
            extension_info=ext_info)
        CONF.set_override('extensions_blacklist', 'os-multiple-create',
                          'osapi_v21')
        self.no_mult_create_controller = servers_v21.ServersController(
            extension_info=ext_info)

        def instance_create(context, inst):
            inst_type = flavors.get_flavor_by_flavor_id(3)
            image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
            def_image_ref = 'http://localhost/images/%s' % image_uuid
            self.instance_cache_num += 1
            instance = fake_instance.fake_db_instance(**{
                'id': self.instance_cache_num,
                'display_name': inst['display_name'] or 'test',
                'uuid': inst['uuid'],
                'instance_type': inst_type,
                'access_ip_v4': '1.2.3.4',
                'access_ip_v6': 'fead::1234',
                'image_ref': inst.get('image_ref', def_image_ref),
                'user_id': 'fake',
                'project_id': 'fake',
                'reservation_id': inst['reservation_id'],
                "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
                "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
                "progress": 0,
                "fixed_ips": [],
                "task_state": "",
                "vm_state": "",
                "security_groups": inst['security_groups'],
            })

            self.instance_cache_by_id[instance['id']] = instance
            self.instance_cache_by_uuid[instance['uuid']] = instance
            return instance

        def instance_get(context, instance_id):
            """Stub for compute/api create() pulling in instance after
            scheduling
            """
            return self.instance_cache_by_id[instance_id]

        def instance_update(context, uuid, values):
            instance = self.instance_cache_by_uuid[uuid]
            instance.update(values)
            return instance

        def server_update(context, instance_uuid, params,
                          columns_to_join=None):
            inst = self.instance_cache_by_uuid[instance_uuid]
            inst.update(params)
            return (inst, inst)

        def fake_method(*args, **kwargs):
            pass

        def project_get_networks(context, user_id):
            return dict(id='1', host='localhost')

        fakes.stub_out_rate_limiting(self.stubs)
        fakes.stub_out_key_pair_funcs(self.stubs)
        fake.stub_out_image_service(self)
        fakes.stub_out_nw_api(self)
        self.stub_out('nova.db.instance_add_security_group',
                      return_security_group)
        self.stub_out('nova.db.project_get_networks', project_get_networks)
        self.stub_out('nova.db.instance_create', instance_create)
        self.stub_out('nova.db.instance_system_metadata_update', fake_method)
        self.stub_out('nova.db.instance_get', instance_get)
        self.stub_out('nova.db.instance_update', instance_update)
        self.stub_out('nova.db.instance_update_and_get_original',
                      server_update)
        self.stubs.Set(manager.VlanManager, 'allocate_fixed_ip',
                       fake_method)
        self.req = fakes.HTTPRequest.blank('')
Exemple #24
0
    def setUp(self):
        """Run before each test."""
        super(ImagesControllerTestV21, self).setUp()
        self.flags(api_servers=['http://localhost:9292'], group='glance')
        fakes.stub_out_networking(self)
        fakes.stub_out_key_pair_funcs(self)
        fakes.stub_out_compute_api_snapshot(self.stubs)
        fakes.stub_out_compute_api_backup(self.stubs)

        self.controller = self.image_controller_class()
        self.url_prefix = "http://localhost%s/images" % self.url_base
        self.bookmark_prefix = "http://localhost%s/images" % self.bookmark_base
        self.uuid = 'fa95aaf5-ab3b-4cd8-88c0-2be7dd051aaf'
        self.server_uuid = "aa640691-d1a7-4a67-9d3c-d35ee6b3cc74"
        self.server_href = (
            "http://localhost%s/servers/%s" % (self.url_base,
                                               self.server_uuid))
        self.server_bookmark = (
             "http://localhost%s/servers/%s" % (self.bookmark_base,
                                                self.server_uuid))
        self.alternate = "%s/images/%s"

        self.expected_image_123 = {
            "image": {'id': '123',
                      'name': 'public image',
                      'metadata': {'key1': 'value1'},
                      'updated': NOW_API_FORMAT,
                      'created': NOW_API_FORMAT,
                      'status': 'ACTIVE',
                      'minDisk': 10,
                      'progress': 100,
                      'minRam': 128,
                      "links": [{
                                    "rel": "self",
                                    "href": "%s/123" % self.url_prefix
                                },
                                {
                                    "rel": "bookmark",
                                    "href":
                                        "%s/123" % self.bookmark_prefix
                                },
                                {
                                    "rel": "alternate",
                                    "type": "application/vnd.openstack.image",
                                    "href": self.alternate %
                                            (glance.generate_glance_url(),
                                             123),
                                }],
            },
        }

        self.expected_image_124 = {
            "image": {'id': '124',
                      'name': 'queued snapshot',
                      'metadata': {
                          u'instance_uuid': self.server_uuid,
                          u'user_id': u'fake',
                      },
                      'updated': NOW_API_FORMAT,
                      'created': NOW_API_FORMAT,
                      'status': 'SAVING',
                      'progress': 25,
                      'minDisk': 0,
                      'minRam': 0,
                      'server': {
                          'id': self.server_uuid,
                          "links": [{
                                        "rel": "self",
                                        "href": self.server_href,
                                    },
                                    {
                                        "rel": "bookmark",
                                        "href": self.server_bookmark,
                                    }],
                      },
                      "links": [{
                                    "rel": "self",
                                    "href": "%s/124" % self.url_prefix
                                },
                                {
                                    "rel": "bookmark",
                                    "href":
                                        "%s/124" % self.bookmark_prefix
                                },
                                {
                                    "rel": "alternate",
                                    "type":
                                        "application/vnd.openstack.image",
                                    "href": self.alternate %
                                            (glance.generate_glance_url(),
                                             124),
                                }],
            },
        }
Exemple #25
0
 def setUp(self):
     super(FlavorsExtraSpecsTestV21, self).setUp()
     fakes.stub_out_key_pair_funcs(self)
     self.controller = self.flavorextraspecs.FlavorExtraSpecsController()
    def setUp(self):
        """Shared implementation for tests below that create instance."""
        super(MultiCreateExtensionTestV2, self).setUp()

        self.flags(verbose=True,
                   enable_instance_password=True)
        self.instance_cache_num = 0
        self.instance_cache_by_id = {}
        self.instance_cache_by_uuid = {}

        fakes.stub_out_nw_api(self)

        self.ext_mgr = extensions_v20.ExtensionManager()
        self.ext_mgr.extensions = {
            'os-volumes': 'fake',
            'os-multiple-create': 'fake',
            'os-block-device-mapping-v2-boot': 'fake'
        }
        self.controller = servers_v20.Controller(self.ext_mgr)

        no_mult_ext_mgr = extensions_v20.ExtensionManager()
        no_mult_ext_mgr.extensions = {
            'os-volumes': 'fake',
            'os-block-device-mapping-v2-boot': 'fake'
        }
        self.no_mult_create_controller = servers_v20.Controller(
            no_mult_ext_mgr)

        def instance_create(context, inst):
            inst_type = flavors.get_flavor_by_flavor_id(3)
            image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
            def_image_ref = 'http://localhost/images/%s' % image_uuid
            self.instance_cache_num += 1
            instance = fake_instance.fake_db_instance(**{
                'id': self.instance_cache_num,
                'display_name': inst['display_name'] or 'test',
                'uuid': inst['uuid'],
                'instance_type': inst_type,
                'access_ip_v4': '1.2.3.4',
                'access_ip_v6': 'fead::1234',
                'image_ref': inst.get('image_ref', def_image_ref),
                'user_id': 'fake',
                'project_id': 'fake',
                'reservation_id': inst['reservation_id'],
                "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
                "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
                "config_drive": None,
                "progress": 0,
                "fixed_ips": [],
                "task_state": "",
                "vm_state": "",
                "root_device_name": inst.get('root_device_name', 'vda'),
                "security_groups": inst['security_groups'],
            })

            self.instance_cache_by_id[instance['id']] = instance
            self.instance_cache_by_uuid[instance['uuid']] = instance
            return instance

        def instance_get(context, instance_id):
            """Stub for compute/api create() pulling in instance after
            scheduling
            """
            return self.instance_cache_by_id[instance_id]

        fakes.stub_out_rate_limiting(self.stubs)
        fakes.stub_out_key_pair_funcs(self.stubs)
        fake.stub_out_image_service(self)
        self.stub_out('nova.db.instance_create', instance_create)
        self.stub_out('nova.db.instance_get', instance_get)
Exemple #27
0
    def setUp(self):
        """Shared implementation for tests below that create instance."""
        super(ServersControllerCreateTest, self).setUp()

        self.flags(enable_instance_password=True, group='api')
        self.instance_cache_num = 0
        self.instance_cache_by_id = {}
        self.instance_cache_by_uuid = {}

        # Network API needs to be stubbed out before creating the controllers.
        fakes.stub_out_nw_api(self)

        self.controller = servers.ServersController()

        def instance_create(context, inst):
            inst_type = flavors.get_flavor_by_flavor_id(3)
            image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
            def_image_ref = 'http://localhost/images/%s' % image_uuid
            self.instance_cache_num += 1
            instance = fake_instance.fake_db_instance(**{
                'id': self.instance_cache_num,
                'display_name': inst['display_name'] or 'test',
                'uuid': FAKE_UUID,
                'instance_type': inst_type,
                'access_ip_v4': '1.2.3.4',
                'access_ip_v6': 'fead::1234',
                'image_ref': inst.get('image_ref', def_image_ref),
                'user_id': 'fake',
                'project_id': 'fake',
                'reservation_id': inst['reservation_id'],
                "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
                "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
                user_data.ATTRIBUTE_NAME: None,
                "progress": 0,
                "fixed_ips": [],
                "task_state": "",
                "vm_state": "",
                "root_device_name": inst.get('root_device_name', 'vda'),
            })

            self.instance_cache_by_id[instance['id']] = instance
            self.instance_cache_by_uuid[instance['uuid']] = instance
            return instance

        def instance_get(context, instance_id):
            """Stub for compute/api create() pulling in instance after
            scheduling
            """
            return self.instance_cache_by_id[instance_id]

        def instance_update(context, uuid, values):
            instance = self.instance_cache_by_uuid[uuid]
            instance.update(values)
            return instance

        def server_update(context, instance_uuid, params):
            inst = self.instance_cache_by_uuid[instance_uuid]
            inst.update(params)
            return (inst, inst)

        def fake_method(*args, **kwargs):
            pass

        def project_get_networks(context, user_id):
            return dict(id='1', host='localhost')

        fakes.stub_out_key_pair_funcs(self)
        fake.stub_out_image_service(self)

        self.stubs.Set(uuid, 'uuid4', fake_gen_uuid)
        self.stub_out('nova.db.instance_add_security_group',
                      return_security_group)
        self.stub_out('nova.db.project_get_networks', project_get_networks)
        self.stub_out('nova.db.instance_create', instance_create)
        self.stub_out('nova.db.instance_system_metadata_update', fake_method)
        self.stub_out('nova.db.instance_get', instance_get)
        self.stub_out('nova.db.instance_update', instance_update)
        self.stub_out('nova.db.instance_update_and_get_original',
                      server_update)
        self.stubs.Set(manager.VlanManager, 'allocate_fixed_ip',
                       fake_method)
Exemple #28
0
    def setUp(self):
        """Shared implementation for tests below that create instance."""
        super(ServersControllerCreateTest, self).setUp()

        self.instance_cache_num = 0
        self.instance_cache_by_id = {}
        self.instance_cache_by_uuid = {}

        ext_info = extension_info.LoadedExtensionInfo()
        self.controller = servers.ServersController(extension_info=ext_info)
        CONF.set_override('extensions_blacklist', preempt_api.ALIAS,
                          'osapi_v21')
        self.no_preemptible_controller = servers.ServersController(
            extension_info=ext_info)

        def instance_create(context, inst):
            inst_type = flavors.get_flavor_by_flavor_id(3)
            image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
            def_image_ref = 'http://localhost/images/%s' % image_uuid
            self.instance_cache_num += 1
            instance = fake_instance.fake_db_instance(**{
                'id': self.instance_cache_num,
                'display_name': inst['display_name'] or 'test',
                'uuid': FAKE_UUID,
                'instance_type': inst_type,
                'access_ip_v4': '1.2.3.4',
                'access_ip_v6': 'fead::1234',
                'image_ref': inst.get('image_ref', def_image_ref),
                'user_id': 'fake',
                'project_id': 'fake',
                'reservation_id': inst['reservation_id'],
                "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
                "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
                "progress": 0,
                "fixed_ips": [],
                "task_state": "",
                "vm_state": "",
                "root_device_name": inst.get('root_device_name', 'vda'),
            })

            self.instance_cache_by_id[instance['id']] = instance
            self.instance_cache_by_uuid[instance['uuid']] = instance
            return instance

        def instance_get(context, instance_id):
            """Stub for compute/api create() pulling in instance after
            scheduling
            """
            return self.instance_cache_by_id[instance_id]

        def instance_update(context, uuid, values):
            instance = self.instance_cache_by_uuid[uuid]
            instance.update(values)
            return instance

        def server_update_and_get_original(context, instance_uuid, params):
            inst = self.instance_cache_by_uuid[instance_uuid]
            inst.update(params)
            return (inst, inst)

        def fake_method(*args, **kwargs):
            pass

        def project_get_networks(context, user_id):
            return dict(id='1', host='localhost')

        os_api_fakes.stub_out_key_pair_funcs(self)
        os_image_fake.stub_out_image_service(self)
        self.stubs.Set(uuid, 'uuid4', fake_gen_uuid)
        self.stub_out('nova.db.project_get_networks', project_get_networks)
        self.stub_out('nova.db.instance_create', instance_create)
        self.stub_out('nova.db.instance_system_metadata_update', fake_method)
        self.stub_out('nova.db.instance_get', instance_get)
        self.stub_out('nova.db.instance_update', instance_update)
        self.stub_out('nova.db.instance_update_and_get_original',
                server_update_and_get_original)
        self.stubs.Set(net_manager.VlanManager, 'allocate_fixed_ip',
                       fake_method)
        self.body = {
            'server': {
                'name': 'server_test',
                'imageRef': self.image_uuid,
                'flavorRef': self.flavor_ref,
                'metadata': {
                    'hello': 'world',
                    'open': 'stack',
                    },
                'personality': [
                    {
                        "path": "/etc/banner.txt",
                        "contents": "MQ==",
                    },
                ],
            },
        }
        self.bdm = [{'delete_on_termination': 1,
                     'device_name': 123,
                     'volume_size': 1,
                     'volume_id': '11111111-1111-1111-1111-111111111111'}]

        self.req = os_api_fakes.HTTPRequest.blank('/fake/servers')
        self.req.method = 'POST'
        self.req.headers["content-type"] = "application/json"
Exemple #29
0
    def setUp(self):
        """Shared implementation for tests below that create instance."""
        super(ServersControllerCreateTest, self).setUp()

        self.flags(verbose=True, enable_instance_password=True)
        self.instance_cache_num = 0
        self.instance_cache_by_id = {}
        self.instance_cache_by_uuid = {}

        ext_info = extension_info.LoadedExtensionInfo()
        self.controller = servers.ServersController(extension_info=ext_info)
        CONF.set_override("extensions_blacklist", "os-user-data", "osapi_v21")
        self.no_user_data_controller = servers.ServersController(extension_info=ext_info)

        def instance_create(context, inst):
            inst_type = flavors.get_flavor_by_flavor_id(3)
            image_uuid = "76fa36fc-c930-4bf3-8c8a-ea2a2420deb6"
            def_image_ref = "http://localhost/images/%s" % image_uuid
            self.instance_cache_num += 1
            instance = fake_instance.fake_db_instance(
                **{
                    "id": self.instance_cache_num,
                    "display_name": inst["display_name"] or "test",
                    "uuid": FAKE_UUID,
                    "instance_type": inst_type,
                    "access_ip_v4": "1.2.3.4",
                    "access_ip_v6": "fead::1234",
                    "image_ref": inst.get("image_ref", def_image_ref),
                    "user_id": "fake",
                    "project_id": "fake",
                    "reservation_id": inst["reservation_id"],
                    "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
                    "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
                    user_data.ATTRIBUTE_NAME: None,
                    "progress": 0,
                    "fixed_ips": [],
                    "task_state": "",
                    "vm_state": "",
                    "root_device_name": inst.get("root_device_name", "vda"),
                }
            )

            self.instance_cache_by_id[instance["id"]] = instance
            self.instance_cache_by_uuid[instance["uuid"]] = instance
            return instance

        def instance_get(context, instance_id):
            """Stub for compute/api create() pulling in instance after
            scheduling
            """
            return self.instance_cache_by_id[instance_id]

        def instance_update(context, uuid, values):
            instance = self.instance_cache_by_uuid[uuid]
            instance.update(values)
            return instance

        def server_update(context, instance_uuid, params):
            inst = self.instance_cache_by_uuid[instance_uuid]
            inst.update(params)
            return (inst, inst)

        def fake_method(*args, **kwargs):
            pass

        def project_get_networks(context, user_id):
            return dict(id="1", host="localhost")

        fakes.stub_out_rate_limiting(self.stubs)
        fakes.stub_out_key_pair_funcs(self.stubs)
        fake.stub_out_image_service(self)
        fakes.stub_out_nw_api(self.stubs)
        self.stubs.Set(uuid, "uuid4", fake_gen_uuid)
        self.stubs.Set(db, "instance_add_security_group", return_security_group)
        self.stubs.Set(db, "project_get_networks", project_get_networks)
        self.stubs.Set(db, "instance_create", instance_create)
        self.stubs.Set(db, "instance_system_metadata_update", fake_method)
        self.stubs.Set(db, "instance_get", instance_get)
        self.stubs.Set(db, "instance_update", instance_update)
        self.stubs.Set(db, "instance_update_and_get_original", server_update)
        self.stubs.Set(manager.VlanManager, "allocate_fixed_ip", fake_method)