Python oslo_serialization.jsonutils.dump_as_bytes() Examples

The following are code examples for showing how to use oslo_serialization.jsonutils.dump_as_bytes(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_disk_config.py    Apache License 2.0 6 votes vote down vote up
def test_create_server_with_auto_disk_config(self):
        req = fakes.HTTPRequest.blank('/fake/servers')
        req.method = 'POST'
        req.content_type = 'application/json'
        body = {'server': {
                  'name': 'server_test',
                  'imageRef': 'cedef40a-ed67-4d10-800e-17455edce175',
                  'flavorRef': '1',
                  API_DISK_CONFIG: 'AUTO'
               }}
        old_create = compute_api.API.create

        def create(*args, **kwargs):
            self.assertIn('auto_disk_config', kwargs)
            self.assertTrue(kwargs['auto_disk_config'])
            return old_create(*args, **kwargs)

        self.stubs.Set(compute_api.API, 'create', create)

        req.body = jsonutils.dump_as_bytes(body)
        res = req.get_response(self.app)
        server_dict = jsonutils.loads(res.body)['server']
        self.assertDiskConfig(server_dict, 'AUTO') 
Example 2
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_disk_config.py    Apache License 2.0 6 votes vote down vote up
def test_rebuild_server_with_auto_disk_config(self):
        req = fakes.HTTPRequest.blank(
            '/fake/servers/%s/action' % AUTO_INSTANCE_UUID)
        req.method = 'POST'
        req.content_type = 'application/json'
        body = {"rebuild": {
                  'imageRef': 'cedef40a-ed67-4d10-800e-17455edce175',
                  API_DISK_CONFIG: 'AUTO'
               }}

        def rebuild(*args, **kwargs):
            self.assertIn('auto_disk_config', kwargs)
            self.assertTrue(kwargs['auto_disk_config'])

        self.stubs.Set(compute_api.API, 'rebuild', rebuild)

        req.body = jsonutils.dump_as_bytes(body)
        res = req.get_response(self.app)
        server_dict = jsonutils.loads(res.body)['server']
        self.assertDiskConfig(server_dict, 'AUTO') 
Example 3
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_disk_config.py    Apache License 2.0 6 votes vote down vote up
def test_resize_server_with_auto_disk_config(self):
        req = fakes.HTTPRequest.blank(
            '/fake/servers/%s/action' % AUTO_INSTANCE_UUID)
        req.method = 'POST'
        req.content_type = 'application/json'
        body = {"resize": {
                    "flavorRef": "3",
                    API_DISK_CONFIG: 'AUTO'
               }}

        def resize(*args, **kwargs):
            self.assertIn('auto_disk_config', kwargs)
            self.assertTrue(kwargs['auto_disk_config'])

        self.stubs.Set(compute_api.API, 'resize', resize)

        req.body = jsonutils.dump_as_bytes(body)
        req.get_response(self.app) 
Example 4
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_extensions.py    Apache License 2.0 6 votes vote down vote up
def test_controller_action_extension_early(self):
        controller = StubActionController(response_body)
        actions = dict(action='POST')
        res_ext = base_extensions.ResourceExtension('tweedles', controller,
                                                    member_actions=actions)
        ext_controller = StubEarlyExtensionController(extension_body)
        extension = StubControllerExtension()
        cont_ext = base_extensions.ControllerExtension(extension, 'tweedles',
                                                       ext_controller)
        manager = StubExtensionManager(resource_ext=res_ext,
                                       controller_ext=cont_ext)
        app = compute.APIRouter(manager)
        request = webob.Request.blank("/fake/tweedles/foo/action")
        request.method = 'POST'
        request.headers['Content-Type'] = 'application/json'
        request.body = jsonutils.dump_as_bytes(dict(fooAction=True))
        response = request.get_response(app)
        self.assertEqual(200, response.status_int)
        self.assertEqual(extension_body, response.body) 
Example 5
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_extensions.py    Apache License 2.0 6 votes vote down vote up
def test_controller_action_extension_late(self):
        # Need a dict for the body to convert to a ResponseObject
        controller = StubActionController(dict(foo=response_body))
        actions = dict(action='POST')
        res_ext = base_extensions.ResourceExtension('tweedles', controller,
                                                    member_actions=actions)

        ext_controller = StubLateExtensionController(extension_body)
        extension = StubControllerExtension()
        cont_ext = base_extensions.ControllerExtension(extension, 'tweedles',
                                                       ext_controller)

        manager = StubExtensionManager(resource_ext=res_ext,
                                       controller_ext=cont_ext)
        app = compute.APIRouter(manager)
        request = webob.Request.blank("/fake/tweedles/foo/action")
        request.method = 'POST'
        request.headers['Content-Type'] = 'application/json'
        request.body = jsonutils.dump_as_bytes(dict(fooAction=True))
        response = request.get_response(app)
        self.assertEqual(200, response.status_int)
        self.assertEqual(extension_body, response.body) 
Example 6
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 6 votes vote down vote up
def test_update_server_adminPass_ignored(self):
        inst_dict = dict(name='server_test', adminPass='bacon')
        body = dict(server=inst_dict)

        def server_update(context, id, params):
            filtered_dict = {
                'display_name': 'server_test',
            }
            self.assertEqual(filtered_dict, params)
            filtered_dict['uuid'] = id
            return filtered_dict

        self.stub_out('nova.db.instance_update', server_update)
        # FIXME (comstud)
        #        self.stub_out('nova.db.instance_get',
        #                return_server_with_attributes(name='server_test'))

        req = fakes.HTTPRequest.blank('/fake/servers/%s' % FAKE_UUID)
        req.method = 'PUT'
        req.content_type = "application/json"
        req.body = jsonutils.dump_as_bytes(body)
        res_dict = self.controller.update(req, FAKE_UUID, body)

        self.assertEqual(FAKE_UUID, res_dict['server']['id'])
        self.assertEqual('server_test', res_dict['server']['name']) 
Example 7
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 6 votes vote down vote up
def test_rebuild_instance_onset_file_limit_over_quota(self):
        def fake_get_image(self, context, image_href, **kwargs):
            return dict(id='76fa36fc-c930-4bf3-8c8a-ea2a2420deb6',
                        name='public image', is_public=True, status='active')

        with test.nested(
            mock.patch.object(fake._FakeImageService, 'show',
                              side_effect=fake_get_image),
            mock.patch.object(self.controller.compute_api, 'rebuild',
                              side_effect=exception.OnsetFileLimitExceeded)
        ) as (
            show_mock, rebuild_mock
        ):
            self.req.body = jsonutils.dump_as_bytes(self.body)
            self.assertRaises(webob.exc.HTTPForbidden,
                              self.controller._action_rebuild,
                              self.req, FAKE_UUID, body=self.body) 
Example 8
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 6 votes vote down vote up
def test_create_server_image_too_large(self):
        image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
        # Get the fake image service so we can update the size of the image
        (image_service, image_id) = glance.get_remote_image_service(context,
                                                                    image_uuid)
        image = image_service.show(context, image_id)
        orig_size = image['size']
        new_size = str(1000 * (1024 ** 3))
        image_service.update(context, image_uuid, {'size': new_size})

        self.addCleanup(image_service.update, context, image_uuid,
                        {'size': orig_size})

        self.body['server']['flavorRef'] = 2
        self.req.body = jsonutils.dump_as_bytes(self.body)
        with testtools.ExpectedException(
                webob.exc.HTTPBadRequest,
                "Flavor's disk is too small for requested image."):
            self.controller.create(self.req, self.body) 
Example 9
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 6 votes vote down vote up
def test_create_instance_invalid_personality(self):

        def fake_create(*args, **kwargs):
            codec = 'utf8'
            content = 'b25zLiINCg0KLVJpY2hhcmQgQ$$%QQmFjaA=='
            start_position = 19
            end_position = 20
            msg = 'invalid start byte'
            raise UnicodeDecodeError(codec, content, start_position,
                                     end_position, msg)
        self.stubs.Set(compute_api.API, 'create', fake_create)
        self.body['server']['personality'] = [
            {
                "path": "/etc/banner.txt",
                "contents": "b25zLiINCg0KLVJpY2hhcmQgQ$$%QQmFjaA==",
            },
        ]
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.create, self.req, self.body) 
Example 10
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 6 votes vote down vote up
def test_create_instance_with_group_hint(self):
        ctxt = self.req.environ['nova.context']
        test_group = objects.InstanceGroup(ctxt)
        test_group.project_id = ctxt.project_id
        test_group.user_id = ctxt.user_id
        test_group.create()

        def fake_instance_destroy(context, uuid, constraint):
            return fakes.stub_instance(1)

        self.stub_out('nova.db.instance_destroy', fake_instance_destroy)
        self.ext_mgr.extensions = {'OS-SCH-HNT': 'fake',
                                   'os-server-group-quotas': 'fake'}
        self.body['server']['scheduler_hints'] = {'group': test_group.uuid}
        self.req.body = jsonutils.dump_as_bytes(self.body)
        server = self.controller.create(self.req, self.body).obj['server']

        test_group = objects.InstanceGroup.get_by_uuid(ctxt, test_group.uuid)
        self.assertIn(server['id'], test_group.members) 
Example 11
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_serversV21.py    Apache License 2.0 6 votes vote down vote up
def test_rebuild_instance_onset_file_limit_over_quota(self):
        def fake_get_image(self, context, image_href, **kwargs):
            return dict(id='76fa36fc-c930-4bf3-8c8a-ea2a2420deb6',
                        name='public image', is_public=True, status='active')

        with test.nested(
            mock.patch.object(fake._FakeImageService, 'show',
                              side_effect=fake_get_image),
            mock.patch.object(self.controller.compute_api, 'rebuild',
                              side_effect=exception.OnsetFileLimitExceeded)
        ) as (
            show_mock, rebuild_mock
        ):
            self.req.body = jsonutils.dump_as_bytes(self.body)
            self.assertRaises(webob.exc.HTTPForbidden,
                              self.controller._action_rebuild,
                              self.req, FAKE_UUID, body=self.body) 
Example 12
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: base.py    Apache License 2.0 5 votes vote down vote up
def _network_data(self, version, path):
        if self.network_metadata is None:
            return jsonutils.dump_as_bytes({})
        return jsonutils.dump_as_bytes(self.network_metadata) 
Example 13
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: base.py    Apache License 2.0 5 votes vote down vote up
def _vendor_data(self, version, path):
        if self._check_os_version(HAVANA, version):
            self.set_mimetype(MIME_TYPE_APPLICATION_JSON)
            return jsonutils.dump_as_bytes(self.vddriver.get())
        raise KeyError(path) 
Example 14
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: base.py    Apache License 2.0 5 votes vote down vote up
def metadata_for_config_drive(self):
        """Yields (path, value) tuples for metadata elements."""
        # EC2 style metadata
        for version in VERSIONS + ["latest"]:
            if version in CONF.config_drive_skip_versions.split(' '):
                continue

            data = self.get_ec2_metadata(version)
            if 'user-data' in data:
                filepath = os.path.join('ec2', version, 'user-data')
                yield (filepath, data['user-data'])
                del data['user-data']

            try:
                del data['public-keys']['0']['_name']
            except KeyError:
                pass

            filepath = os.path.join('ec2', version, 'meta-data.json')
            yield (filepath, jsonutils.dump_as_bytes(data['meta-data']))

        ALL_OPENSTACK_VERSIONS = OPENSTACK_VERSIONS + ["latest"]
        for version in ALL_OPENSTACK_VERSIONS:
            path = 'openstack/%s/%s' % (version, MD_JSON_NAME)
            yield (path, self.lookup(path))

            path = 'openstack/%s/%s' % (version, UD_NAME)
            if self.userdata_raw is not None:
                yield (path, self.lookup(path))

            if self._check_version(HAVANA, version, ALL_OPENSTACK_VERSIONS):
                path = 'openstack/%s/%s' % (version, VD_JSON_NAME)
                yield (path, self.lookup(path))

            if self._check_version(LIBERTY, version, ALL_OPENSTACK_VERSIONS):
                path = 'openstack/%s/%s' % (version, NW_JSON_NAME)
                yield (path, self.lookup(path))

        for (cid, content) in six.iteritems(self.content):
            yield ('%s/%s/%s' % ("openstack", CONTENT_DIR, cid), content) 
Example 15
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_createserverext.py    Apache License 2.0 5 votes vote down vote up
def _get_create_request_json(self, body_dict):
        req = webob.Request.blank('/v2/fake/os-create-server-ext')
        req.headers['Content-Type'] = 'application/json'
        req.method = 'POST'
        req.body = jsonutils.dump_as_bytes(body_dict)
        return req 
Example 16
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_disk_config.py    Apache License 2.0 5 votes vote down vote up
def test_create_server_override_manual(self):
        req = fakes.HTTPRequest.blank('/fake/servers')
        req.method = 'POST'
        req.content_type = 'application/json'
        body = {'server': {
                  'name': 'server_test',
                  'imageRef': 'cedef40a-ed67-4d10-800e-17455edce175',
                  'flavorRef': '1',
                  API_DISK_CONFIG: 'MANUAL'
               }}

        req.body = jsonutils.dump_as_bytes(body)
        res = req.get_response(self.app)
        server_dict = jsonutils.loads(res.body)['server']
        self.assertDiskConfig(server_dict, 'MANUAL') 
Example 17
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_disk_config.py    Apache License 2.0 5 votes vote down vote up
def test_create_server_detect_from_image(self):
        """If user doesn't pass in diskConfig for server, use image metadata
        to specify AUTO or MANUAL.
        """
        req = fakes.HTTPRequest.blank('/fake/servers')
        req.method = 'POST'
        req.content_type = 'application/json'
        body = {'server': {
                  'name': 'server_test',
                  'imageRef': 'a440c04b-79fa-479c-bed1-0b816eaec379',
                  'flavorRef': '1',
               }}

        req.body = jsonutils.dump_as_bytes(body)
        res = req.get_response(self.app)
        server_dict = jsonutils.loads(res.body)['server']
        self.assertDiskConfig(server_dict, 'MANUAL')

        req = fakes.HTTPRequest.blank('/fake/servers')
        req.method = 'POST'
        req.content_type = 'application/json'
        body = {'server': {
                  'name': 'server_test',
                  'imageRef': '70a599e0-31e7-49b7-b260-868f441e862b',
                  'flavorRef': '1',
               }}

        req.body = jsonutils.dump_as_bytes(body)
        res = req.get_response(self.app)
        server_dict = jsonutils.loads(res.body)['server']
        self.assertDiskConfig(server_dict, 'AUTO') 
Example 18
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_disk_config.py    Apache License 2.0 5 votes vote down vote up
def test_create_server_detect_from_image_disabled_goes_to_manual(self):
        req = fakes.HTTPRequest.blank('/fake/servers')
        req.method = 'POST'
        req.content_type = 'application/json'
        body = {'server': {
                  'name': 'server_test',
                  'imageRef': '88580842-f50a-11e2-8d3a-f23c91aec05e',
                  'flavorRef': '1',
               }}

        req.body = jsonutils.dump_as_bytes(body)
        res = req.get_response(self.app)
        server_dict = jsonutils.loads(res.body)['server']
        self.assertDiskConfig(server_dict, 'MANUAL') 
Example 19
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_disk_config.py    Apache License 2.0 5 votes vote down vote up
def test_create_server_errors_when_disabled_and_auto(self):
        req = fakes.HTTPRequest.blank('/fake/servers')
        req.method = 'POST'
        req.content_type = 'application/json'
        body = {'server': {
                  'name': 'server_test',
                  'imageRef': '88580842-f50a-11e2-8d3a-f23c91aec05e',
                  'flavorRef': '1',
                  API_DISK_CONFIG: 'AUTO'
               }}

        req.body = jsonutils.dump_as_bytes(body)
        res = req.get_response(self.app)
        self.assertEqual(res.status_int, 400) 
Example 20
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_disk_config.py    Apache License 2.0 5 votes vote down vote up
def test_create_server_when_disabled_and_manual(self):
        req = fakes.HTTPRequest.blank('/fake/servers')
        req.method = 'POST'
        req.content_type = 'application/json'
        body = {'server': {
                  'name': 'server_test',
                  'imageRef': '88580842-f50a-11e2-8d3a-f23c91aec05e',
                  'flavorRef': '1',
                  API_DISK_CONFIG: 'MANUAL'
               }}

        req.body = jsonutils.dump_as_bytes(body)
        res = req.get_response(self.app)
        server_dict = jsonutils.loads(res.body)['server']
        self.assertDiskConfig(server_dict, 'MANUAL') 
Example 21
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_disk_config.py    Apache License 2.0 5 votes vote down vote up
def test_update_server_invalid_disk_config(self):
        # Return BadRequest if user passes an invalid diskConfig value.
        req = fakes.HTTPRequest.blank(
            '/fake/servers/%s' % MANUAL_INSTANCE_UUID)
        req.method = 'PUT'
        req.content_type = 'application/json'
        body = {'server': {API_DISK_CONFIG: 'server_test'}}
        req.body = jsonutils.dump_as_bytes(body)
        res = req.get_response(self.app)
        self.assertEqual(res.status_int, 400)
        expected_msg = self._get_expected_msg_for_invalid_disk_config()
        expected_msg = expected_msg.format(API_DISK_CONFIG, 'server_test')

        self.assertEqual(jsonutils.loads(expected_msg),
                         jsonutils.loads(res.body)) 
Example 22
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_disk_config.py    Apache License 2.0 5 votes vote down vote up
def _test_rebuild_server_disk_config(self, uuid, disk_config):
        req = fakes.HTTPRequest.blank(
            '/fake/servers/%s/action' % uuid)
        req.method = 'POST'
        req.content_type = 'application/json'
        body = {"rebuild": {
                  'imageRef': 'cedef40a-ed67-4d10-800e-17455edce175',
                  API_DISK_CONFIG: disk_config
               }}
        req.body = jsonutils.dump_as_bytes(body)
        res = req.get_response(self.app)
        server_dict = jsonutils.loads(res.body)['server']
        self.assertDiskConfig(server_dict, disk_config) 
Example 23
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def _get_request(self, body=None, content_type='json', options=None):
        if options:
            self.stubs.Set(compute_api.API, 'get',
                           fakes.fake_compute_get(**options))
        req = fakes.HTTPRequest.blank('/fake/servers/%s' % FAKE_UUID)
        req.method = 'PUT'
        req.content_type = 'application/%s' % content_type
        req.body = jsonutils.dump_as_bytes(body)
        return req 
Example 24
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_rebuild_instance_with_blank_metadata_key(self):
        self.body['rebuild']['accessIPv4'] = '0.0.0.0'
        self.body['rebuild']['accessIPv6'] = 'fead::1234'
        self.body['rebuild']['metadata'][''] = 'world'
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller._action_rebuild,
                          self.req, FAKE_UUID, self.body) 
Example 25
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_rebuild_instance_name_with_spaces_in_middle(self):
        self.body['rebuild']['name'] = 'abc   def'
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.controller._action_rebuild(self.req, FAKE_UUID, self.body) 
Example 26
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_rebuild_instance_with_metadata_key_too_long(self):
        self.body['rebuild']['accessIPv4'] = '0.0.0.0'
        self.body['rebuild']['accessIPv6'] = 'fead::1234'
        self.body['rebuild']['metadata'][('a' * 260)] = 'world'

        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
                          self.controller._action_rebuild,
                          self.req, FAKE_UUID, self.body) 
Example 27
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_rebuild_instance_with_metadata_value_too_long(self):
        self.body['rebuild']['accessIPv4'] = '0.0.0.0'
        self.body['rebuild']['accessIPv6'] = 'fead::1234'
        self.body['rebuild']['metadata']['key1'] = ('a' * 260)

        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
                          self.controller._action_rebuild,
                          self.req, FAKE_UUID, self.body) 
Example 28
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_rebuild_instance_fails_when_min_ram_too_small(self):
        # make min_ram larger than our instance ram size
        def fake_get_image(self, context, image_href, **kwargs):
            return dict(id='76fa36fc-c930-4bf3-8c8a-ea2a2420deb6',
                        name='public image', is_public=True,
                        status='active', properties={'key1': 'value1'},
                        min_ram="4096", min_disk="10")

        self.stubs.Set(fake._FakeImageService, 'show', fake_get_image)

        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller._action_rebuild,
                          self.req, FAKE_UUID, self.body) 
Example 29
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_rebuild_instance_fails_when_min_disk_too_small(self):
        # make min_disk larger than our instance disk size
        def fake_get_image(self, context, image_href, **kwargs):
            return dict(id='76fa36fc-c930-4bf3-8c8a-ea2a2420deb6',
                        name='public image', is_public=True,
                        status='active', properties={'key1': 'value1'},
                        min_ram="128", min_disk="100000")

        self.stubs.Set(fake._FakeImageService, 'show', fake_get_image)
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller._action_rebuild, self.req,
                          FAKE_UUID, self.body) 
Example 30
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_rebuild_instance_with_deleted_image(self):
        def fake_get_image(self, context, image_href, **kwargs):
            return dict(id='76fa36fc-c930-4bf3-8c8a-ea2a2420deb6',
                        name='public image', is_public=True,
                        status='DELETED')

        self.stubs.Set(fake._FakeImageService, 'show', fake_get_image)

        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(webob.exc.HTTPBadRequest,
            self.controller._action_rebuild, self.req, FAKE_UUID, self.body) 
Example 31
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_rebuild_instance_with_null_image_ref(self):
        self.body['rebuild']['imageRef'] = None
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(webob.exc.HTTPBadRequest,
                self.controller._action_rebuild, self.req, FAKE_UUID,
                self.body) 
Example 32
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def _test_create_instance(self, flavor=2):
        image_uuid = 'c905cedb-7281-47e4-8a62-f26bc5fc4c77'
        self.body['server']['imageRef'] = image_uuid
        self.body['server']['flavorRef'] = flavor
        self.req.body = jsonutils.dump_as_bytes(self.body)
        server = self.controller.create(self.req, self.body).obj['server']
        self._check_admin_pass_len(server)
        instance = self.instance_cache_by_uuid.values()[0]
        self.assertEqual(instance['uuid'], server['id'])
        return server 
Example 33
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_server_bad_image_href(self):
        image_href = 1
        self.body['server']['imageRef'] = image_href,
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.create,
                          self.req, self.body) 
Example 34
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_server_with_deleted_image(self):
        image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
        # Get the fake image service so we can set the status to deleted
        (image_service, image_id) = glance.get_remote_image_service(
                context, '')
        image_service.update(context, image_uuid, {'status': 'DELETED'})
        self.addCleanup(image_service.update, context, image_uuid,
                        {'status': 'active'})

        self.body['server']['flavorRef'] = 2
        self.req.body = jsonutils.dump_as_bytes(self.body)
        with testtools.ExpectedException(
                webob.exc.HTTPBadRequest,
                'Image 76fa36fc-c930-4bf3-8c8a-ea2a2420deb6 is not active.'):
            self.controller.create(self.req, self.body) 
Example 35
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_multiple_instances(self):
        """Test creating multiple instances but not asking for
        reservation_id
        """
        self.ext_mgr.extensions = {'os-multiple-create': 'fake'}
        self.req.body = jsonutils.dump_as_bytes(self.body)
        res = self.controller.create(self.req, self.body).obj
        instance_uuids = self.instance_cache_by_uuid.keys()
        self.assertIn(res["server"]["id"], instance_uuids)
        self._check_admin_pass_len(res["server"]) 
Example 36
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_multiple_instances_pass_disabled(self):
        """Test creating multiple instances but not asking for
        reservation_id
        """
        self.ext_mgr.extensions = {'os-multiple-create': 'fake'}
        self.flags(enable_instance_password=False)
        self.req.body = jsonutils.dump_as_bytes(self.body)
        res = self.controller.create(self.req, self.body).obj
        instance_uuids = self.instance_cache_by_uuid.keys()
        self.assertIn(res["server"]["id"], instance_uuids)
        self._check_admin_pass_missing(res["server"]) 
Example 37
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_multiple_instances_resv_id_return(self):
        """Test creating multiple instances with asking for
        reservation_id
        """
        self.ext_mgr.extensions = {'os-multiple-create': 'fake'}
        self.body['server']['return_reservation_id'] = True
        self.req.body = jsonutils.dump_as_bytes(self.body)
        res = self.controller.create(self.req, self.body)
        reservation_id = res.obj.get('reservation_id')
        self.assertNotEqual(reservation_id, "")
        self.assertIsNotNone(reservation_id)
        self.assertTrue(len(reservation_id) > 1) 
Example 38
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_instance_image_ref_is_invalid(self):
        image_uuid = 'this_is_not_a_valid_uuid'
        image_href = 'http://localhost/fake/images/%s' % image_uuid
        self.body['server']['imageRef'] = image_href
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create,
                          self.req, self.body) 
Example 39
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def _test_create_extra(self, params, no_image=False):
        self.body['server']['flavorRef'] = 2
        if no_image:
            self.body['server'].pop('imageRef', None)
        self.body['server'].update(params)
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertIn('server',
                      self.controller.create(self.req, self.body).obj) 
Example 40
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_instance_name_all_blank_spaces(self):
        self.body['server']['name'] = ' ' * 64
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.create, self.req, self.body) 
Example 41
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_instance_name_with_spaces_in_middle(self):
        self.body['server']['name'] = 'abc   def'
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.controller.create(self.req, self.body) 
Example 42
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_instance_name_too_long(self):
        self.body['server']['name'] = 'X' * 256
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create,
                          self.req, self.body) 
Example 43
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_instance_az_with_leading_trailing_spaces(self):
        self.body['server']['availability_zone'] = '  zone1   '
        self.req.body = jsonutils.dump_as_bytes(self.body)
        with mock.patch.object(availability_zones, 'get_availability_zones',
                               return_value=['  zone1  ']):
            self._test_create_instance() 
Example 44
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_instance(self):
        self.req.body = jsonutils.dump_as_bytes(self.body)
        res = self.controller.create(self.req, self.body).obj

        server = res['server']
        self._check_admin_pass_len(server)
        instance = self.instance_cache_by_uuid.values()[0]
        self.assertEqual(instance['uuid'], server['id']) 
Example 45
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_instance_pass_disabled(self):
        self.flags(enable_instance_password=False)
        self.req.body = jsonutils.dump_as_bytes(self.body)
        res = self.controller.create(self.req, self.body).obj

        server = res['server']
        self._check_admin_pass_missing(server)
        instance = self.instance_cache_by_uuid.values()[0]
        self.assertEqual(instance['uuid'], server['id']) 
Example 46
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_instance_numa_topology_wrong(self, numa_constraints_mock):
        numa_constraints_mock.side_effect = (
                exception.ImageNUMATopologyIncomplete)
        image_href = 'http://localhost/v2/images/%s' % self.image_uuid
        self.body['server']['imageRef'] = image_href
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.create, self.req, self.body) 
Example 47
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_instance_too_much_metadata(self):
        self.flags(quota_metadata_items=1)
        self.body['server']['metadata']['vote'] = 'fiddletown'
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(webob.exc.HTTPForbidden,
                          self.controller.create, self.req, self.body) 
Example 48
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_instance_metadata_value_too_long(self):
        self.flags(quota_metadata_items=1)
        self.body['server']['metadata'] = {'key1': ('a' * 260)}
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
                          self.controller.create, self.req, self.body) 
Example 49
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_instance_metadata_key_blank(self):
        self.flags(quota_metadata_items=1)
        self.body['server']['metadata'] = {'': 'abcd'}
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.create, self.req, self.body) 
Example 50
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_instance_metadata_not_dict(self):
        self.flags(quota_metadata_items=1)
        self.body['server']['metadata'] = 'string'
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.create, self.req, self.body) 
Example 51
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_instance_metadata_key_not_string(self):
        self.flags(quota_metadata_items=1)
        self.body['server']['metadata'] = {1: 'test'}
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.create, self.req, self.body) 
Example 52
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_instance_metadata_value_not_string(self):
        self.flags(quota_metadata_items=1)
        self.body['server']['metadata'] = {'test': ['a', 'list']}
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.create, self.req, self.body) 
Example 53
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_instance_empty_key_name(self, mock_create):
        self.body['server']['key_name'] = ''
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.create, self.req, self.body) 
Example 54
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_instance_valid_key_name(self):
        self.body['server']['key_name'] = 'key'
        self.req.body = jsonutils.dump_as_bytes(self.body)
        res = self.controller.create(self.req, self.body).obj

        instance = self.instance_cache_by_uuid.values()[0]
        self.assertEqual(instance['uuid'], res["server"]["id"])
        self._check_admin_pass_len(res["server"]) 
Example 55
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_instance_invalid_flavor_href(self):
        flavor_ref = 'http://localhost/v2/flavors/asdf'
        self.body['server']['flavorRef'] = flavor_ref
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.create, self.req, self.body) 
Example 56
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_instance_invalid_flavor_id_int(self):
        flavor_ref = -1
        self.body['server']['flavorRef'] = flavor_ref
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.create, self.req, self.body) 
Example 57
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_instance_invalid_flavor_id_empty(self):
        flavor_ref = ""
        self.body['server']['flavorRef'] = flavor_ref
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.create, self.req, self.body) 
Example 58
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_instance_with_config_drive(self):
        self.ext_mgr.extensions = {'os-config-drive': 'fake'}
        self.body['server']['config_drive'] = "true"
        self.req.body = jsonutils.dump_as_bytes(self.body)
        res = self.controller.create(self.req, self.body).obj
        server = res['server']
        instance = self.instance_cache_by_uuid.values()[0]
        self.assertEqual(instance['uuid'], server['id']) 
Example 59
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_instance_with_bad_config_drive(self):
        self.ext_mgr.extensions = {'os-config-drive': 'fake'}
        self.body['server']['config_drive'] = 'adcd'
        self.req.body = jsonutils.dump_as_bytes(self.body)

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.create, self.req, self.body) 
Example 60
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_instance_without_config_drive(self):
        self.ext_mgr.extensions = {'os-config-drive': 'fake'}
        self.req.body = jsonutils.dump_as_bytes(self.body)
        res = self.controller.create(self.req, self.body).obj
        server = res['server']
        instance = self.instance_cache_by_uuid.values()[0]
        self.assertEqual(instance['uuid'], server['id']) 
Example 61
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_instance_bad_href(self):
        image_href = 'asdf'
        self.body['server']['imageRef'] = image_href
        self.req.body = jsonutils.dump_as_bytes(self.body)

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.create, self.req, self.body) 
Example 62
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_instance_local_href(self):
        self.req.body = jsonutils.dump_as_bytes(self.body)
        res = self.controller.create(self.req, self.body).obj

        server = res['server']
        instance = self.instance_cache_by_uuid.values()[0]
        self.assertEqual(instance['uuid'], server['id']) 
Example 63
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_instance_admin_pass_pass_disabled(self):
        self.flags(enable_instance_password=False)
        self.body['server']['flavorRef'] = 3,
        self.body['server']['adminPass'] = 'testpass'
        self.req.body = jsonutils.dump_as_bytes(self.body)
        res = self.controller.create(self.req, self.body).obj

        server = res['server']
        self.assertIn('adminPass', self.body['server'])
        self.assertNotIn('adminPass', server) 
Example 64
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_instance_admin_pass_empty(self):
        self.body['server']['flavorRef'] = 3,
        self.body['server']['adminPass'] = ''
        self.req.body = jsonutils.dump_as_bytes(self.body)

        # The fact that the action doesn't raise is enough validation
        self.controller.create(self.req, self.body) 
Example 65
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def test_create_location(self):
        image_href = 'http://localhost/v2/images/%s' % self.image_uuid
        self.body['server']['imageRef'] = image_href
        self.req.body = jsonutils.dump_as_bytes(self.body)
        robj = self.controller.create(self.req, self.body)
        instance = self.instance_cache_by_uuid.values()[0]
        selfhref = 'http://localhost/v2/fake/servers/%s' % instance['uuid']
        self.assertEqual(selfhref, robj['Location']) 
Example 66
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def _do_test_create_instance_above_quota(self, resource, allowed, quota,
                                             expected_msg):
        fakes.stub_out_instance_quota(self, allowed, quota, resource)
        self.body['server']['flavorRef'] = 3
        self.req.body = jsonutils.dump_as_bytes(self.body)
        try:
            self.controller.create(self.req, self.body).obj['server']
            self.fail('expected quota to be exceeded')
        except webob.exc.HTTPForbidden as e:
            self.assertEqual(expected_msg, e.explanation) 
Example 67
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_servers.py    Apache License 2.0 5 votes vote down vote up
def _test_create_extra(self, params, no_image=False):
        self.body['server']['flavorRef'] = 2
        if no_image:
            self.body['server'].pop('imageRef', None)
        self.body['server'].update(params)
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.controller.create(self.req, self.body).obj['server'] 
Example 68
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_block_device_mapping.py    Apache License 2.0 5 votes vote down vote up
def _test_create(self, params, no_image=False, override_controller=None):
        body = self._get_servers_body(no_image)
        body['server'].update(params)

        req = fakes.HTTPRequest.blank('/v2/fake/servers')
        req.method = 'POST'
        req.headers['content-type'] = 'application/json'

        req.body = jsonutils.dump_as_bytes(body)

        if override_controller:
            override_controller.create(req, body=body).obj['server']
        else:
            self.controller.create(req, body=body).obj['server'] 
Example 69
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_serversV21.py    Apache License 2.0 5 votes vote down vote up
def test_rebuild_instance_name_with_spaces_in_the_middle(self):
        self.body['rebuild']['name'] = 'abc   def'
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.controller._action_rebuild(self.req, FAKE_UUID, body=self.body) 
Example 70
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_serversV21.py    Apache License 2.0 5 votes vote down vote up
def test_rebuild_instance_name_with_leading_trailing_spaces(self):
        self.body['rebuild']['name'] = '  abc   def  '
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(exception.ValidationError,
                          self.controller._action_rebuild,
                          self.req, FAKE_UUID, body=self.body) 
Example 71
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_serversV21.py    Apache License 2.0 5 votes vote down vote up
def test_rebuild_instance_with_blank_metadata_key(self):
        self.body['rebuild']['metadata'][''] = 'world'
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(exception.ValidationError,
                          self.controller._action_rebuild,
                          self.req, FAKE_UUID, body=self.body) 
Example 72
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_serversV21.py    Apache License 2.0 5 votes vote down vote up
def test_rebuild_instance_with_metadata_key_too_long(self):
        self.body['rebuild']['metadata'][('a' * 260)] = 'world'

        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(exception.ValidationError,
                          self.controller._action_rebuild,
                          self.req, FAKE_UUID, body=self.body) 
Example 73
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_serversV21.py    Apache License 2.0 5 votes vote down vote up
def test_rebuild_instance_with_metadata_value_too_long(self):
        self.body['rebuild']['metadata']['key1'] = ('a' * 260)

        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(exception.ValidationError,
                          self.controller._action_rebuild, self.req,
                          FAKE_UUID, body=self.body) 
Example 74
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_serversV21.py    Apache License 2.0 5 votes vote down vote up
def test_rebuild_instance_with_metadata_value_not_string(self):
        self.body['rebuild']['metadata']['key1'] = 1

        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(exception.ValidationError,
                          self.controller._action_rebuild, self.req,
                          FAKE_UUID, body=self.body) 
Example 75
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_serversV21.py    Apache License 2.0 5 votes vote down vote up
def test_rebuild_instance_fails_when_min_ram_too_small(self):
        # make min_ram larger than our instance ram size
        def fake_get_image(self, context, image_href, **kwargs):
            return dict(id='76fa36fc-c930-4bf3-8c8a-ea2a2420deb6',
                        name='public image', is_public=True,
                        status='active', properties={'key1': 'value1'},
                        min_ram="4096", min_disk="10")

        self.stubs.Set(fake._FakeImageService, 'show', fake_get_image)

        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller._action_rebuild,
                          self.req, FAKE_UUID, body=self.body) 
Example 76
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_serversV21.py    Apache License 2.0 5 votes vote down vote up
def test_rebuild_instance_image_too_large(self):
        # make image size larger than our instance disk size
        size = str(1000 * (1024 ** 3))

        def fake_get_image(self, context, image_href, **kwargs):
            return dict(id='76fa36fc-c930-4bf3-8c8a-ea2a2420deb6',
                        name='public image', is_public=True,
                        status='active', size=size)

        self.stubs.Set(fake._FakeImageService, 'show', fake_get_image)
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller._action_rebuild,
                          self.req, FAKE_UUID, body=self.body) 
Example 77
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_serversV21.py    Apache License 2.0 5 votes vote down vote up
def test_rebuild_instance_name_all_blank(self):
        def fake_get_image(self, context, image_href, **kwargs):
            return dict(id='76fa36fc-c930-4bf3-8c8a-ea2a2420deb6',
                        name='public image', is_public=True, status='active')

        self.stubs.Set(fake._FakeImageService, 'show', fake_get_image)
        self.body['rebuild']['name'] = '     '
        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(exception.ValidationError,
                          self.controller._action_rebuild,
                          self.req, FAKE_UUID, body=self.body) 
Example 78
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_serversV21.py    Apache License 2.0 5 votes vote down vote up
def test_rebuild_instance_with_deleted_image(self):
        def fake_get_image(self, context, image_href, **kwargs):
            return dict(id='76fa36fc-c930-4bf3-8c8a-ea2a2420deb6',
                        name='public image', is_public=True,
                        status='DELETED')

        self.stubs.Set(fake._FakeImageService, 'show', fake_get_image)

        self.req.body = jsonutils.dump_as_bytes(self.body)
        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller._action_rebuild,
                          self.req, FAKE_UUID, body=self.body) 
Example 79
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_serversV21.py    Apache License 2.0 5 votes vote down vote up
def _rebuild_server(self, set_desc, desc):
        fake_get = fakes.fake_compute_get(vm_state=vm_states.ACTIVE,
                                          display_description=desc)
        self.stubs.Set(compute_api.API, 'get',
                       lambda api, *a, **k: fake_get(*a, **k))

        if set_desc:
            self.body['rebuild']['description'] = desc
        self.req.body = jsonutils.dump_as_bytes(self.body)
        server = self.controller._action_rebuild(self.req, FAKE_UUID,
                                                 body=self.body).obj['server']
        self.assertEqual(server['id'], FAKE_UUID)
        self.assertEqual(server['description'], desc) 
Example 80
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: base.py    Apache License 2.0 4 votes vote down vote up
def _metadata_as_json(self, version, path):
        metadata = {'uuid': self.uuid}
        if self.launch_metadata:
            metadata['meta'] = self.launch_metadata
        if self.files:
            metadata['files'] = self.files
        if self.extra_md:
            metadata.update(self.extra_md)
        if self.network_config:
            metadata['network_config'] = self.network_config
        if self.instance.key_name:
            metadata['public_keys'] = {
                self.instance.key_name: self.instance.key_data
            }

            if cells_opts.get_cell_type() == 'compute':
                cells_api = cells_rpcapi.CellsAPI()
                keypair = cells_api.get_keypair_at_top(
                  context.get_admin_context(), self.instance.user_id,
                  self.instance.key_name)
            else:
                keypair = keypair_obj.KeyPair.get_by_name(
                    context.get_admin_context(), self.instance.user_id,
                    self.instance.key_name)
            metadata['keys'] = [
                {'name': keypair.name,
                 'type': keypair.type,
                 'data': keypair.public_key}
            ]

        metadata['hostname'] = self._get_hostname()
        metadata['name'] = self.instance.display_name
        metadata['launch_index'] = self.instance.launch_index
        metadata['availability_zone'] = self.availability_zone

        if self._check_os_version(GRIZZLY, version):
            metadata['random_seed'] = base64.b64encode(os.urandom(512))

        if self._check_os_version(LIBERTY, version):
            metadata['project_id'] = self.instance.project_id

        self.set_mimetype(MIME_TYPE_APPLICATION_JSON)
        return jsonutils.dump_as_bytes(metadata)