Example #1
0
    def test_request_to_primitive(self):
        spec = copy.deepcopy(self.spec)
        body = profiles.ProfileCreateRequestBody(name='test-profile',
                                                 spec=spec,
                                                 metadata={'x': 'y'})
        sot = profiles.ProfileCreateRequest(profile=body)
        self.assertIsInstance(sot.profile, profiles.ProfileCreateRequestBody)
        self.assertEqual('test-profile', sot.profile.name)
        self.assertEqual({'x': 'y'}, sot.profile.metadata)

        # request
        res = sot.obj_to_primitive()
        self.assertIn('profile', res['senlin_object.changes'])
        self.assertEqual('ProfileCreateRequest', res['senlin_object.name'])
        self.assertEqual('senlin', res['senlin_object.namespace'])
        self.assertEqual('1.0', res['senlin_object.version'])

        # request body
        data = res['senlin_object.data']['profile']
        self.assertEqual('ProfileCreateRequestBody',
                         data['senlin_object.name'])
        self.assertEqual('senlin', data['senlin_object.namespace'])
        self.assertEqual('1.0', data['senlin_object.version'])
        self.assertIn('name', data['senlin_object.changes'])
        self.assertIn('spec', data['senlin_object.changes'])
        self.assertIn('metadata', data['senlin_object.changes'])

        # spec
        pd = data['senlin_object.data']
        self.assertEqual(u'test-profile', pd['name'])

        spec_data = jsonutils.loads(pd['spec'])
        self.assertEqual(u'os.nova.server', spec_data['type'])
        self.assertEqual(u'1.0', spec_data['version'])
Example #2
0
    def test_profile_create2_name_conflict(self, mock_get):
        cfg.CONF.set_override('name_unique', True, enforce_type=True)
        mock_get.return_value = mock.Mock()

        spec = {
            'type': 'FakeProfile',
            'version': '1.0',
            'properties': {
                'LIST': ['A', 'B'],
                'MAP': {
                    'KEY1': 11,
                    'KEY2': 12
                },
            }
        }

        body = vorp.ProfileCreateRequestBody(name='FAKE_NAME', spec=spec)
        req = vorp.ProfileCreateRequest(profile=body)
        ex = self.assertRaises(rpc.ExpectedException, self.eng.profile_create2,
                               self.ctx, req.obj_to_primitive())
        self.assertEqual(exc.BadRequest, ex.exc_info[0])
        self.assertEqual(
            "The request is malformed: A profile named "
            "'FAKE_NAME' already exists.", six.text_type(ex.exc_info[1]))
        mock_get.assert_called_once_with(self.ctx, 'FAKE_NAME')
Example #3
0
 def test_profile_create_request(self):
     spec = copy.deepcopy(self.spec)
     body = profiles.ProfileCreateRequestBody(name='foo',
                                              spec=spec,
                                              metadata={'x': 'y'})
     sot = profiles.ProfileCreateRequest(profile=body)
     self.assertIsInstance(sot.profile, profiles.ProfileCreateRequestBody)
Example #4
0
 def test_profile_create_body(self):
     spec = copy.deepcopy(self.spec)
     sot = profiles.ProfileCreateRequestBody(name='foo', spec=spec,
                                             metadata={'x': 'y'})
     self.assertEqual('foo', sot.name)
     self.assertEqual({'x': 'y'}, sot.metadata)
     self.assertEqual(u'os.nova.server', sot.spec['type'])
     self.assertEqual(u'1.0', sot.spec['version'])
Example #5
0
    def test_profile_create_invalid_spec(self, mock_create):
        self._setup_fakes()
        mock_create.side_effect = exc.InvalidSpec(message="badbad")
        body = vorp.ProfileCreateRequestBody(name='foo', spec=self.spec)
        req = vorp.ProfileCreateRequest(profile=body)
        ex = self.assertRaises(rpc.ExpectedException, self.svc.profile_create,
                               self.ctx, req.obj_to_primitive())

        self.assertEqual(exc.InvalidSpec, ex.exc_info[0])
        self.assertEqual("badbad", six.text_type(ex.exc_info[1]))
Example #6
0
    def test_profile_create_type_not_found(self, mock_create):
        self._setup_fakes()
        spec = copy.deepcopy(self.spec)
        spec['type'] = 'Bogus'
        body = vorp.ProfileCreateRequestBody(name='foo', spec=spec)
        req = vorp.ProfileCreateRequest(profile=body)

        ex = self.assertRaises(rpc.ExpectedException, self.svc.profile_create,
                               self.ctx, req.obj_to_primitive())

        self.assertEqual(exc.ResourceNotFound, ex.exc_info[0])
        self.assertEqual("The profile_type 'Bogus-1.0' could not be "
                         "found.", six.text_type(ex.exc_info[1]))
Example #7
0
    def test_profile_create_default(self, mock_create):
        x_profile = mock.Mock()
        x_profile.to_dict.return_value = {'foo': 'bar'}
        mock_create.return_value = x_profile
        self._setup_fakes()
        body = vorp.ProfileCreateRequestBody(name='p-1',
                                             spec=self.spec,
                                             metadata={'foo': 'bar'})
        req = vorp.ProfileCreateRequest(profile=body)

        result = self.svc.profile_create(self.ctx, req.obj_to_primitive())

        self.assertEqual({'foo': 'bar'}, result)
Example #8
0
    def test_request_body_to_primitive(self):
        spec = copy.deepcopy(self.spec)
        sot = profiles.ProfileCreateRequestBody(name='test-profile',
                                                spec=spec,
                                                metadata={'x': 'y'})
        self.assertEqual('test-profile', sot.name)
        self.assertEqual({'x': 'y'}, sot.metadata)

        res = sot.obj_to_primitive()
        # request body
        self.assertEqual('ProfileCreateRequestBody', res['senlin_object.name'])
        self.assertEqual('1.0', res['senlin_object.version'])
        self.assertEqual('senlin', res['senlin_object.namespace'])
        self.assertIn('name', res['senlin_object.changes'])
        self.assertIn('spec', res['senlin_object.changes'])
        self.assertIn('metadata', res['senlin_object.changes'])
        # spec
        data = res['senlin_object.data']
        self.assertEqual(u'test-profile', data['name'])
        self.assertEqual(u'{"x": "y"}', data['metadata'])
        # spec data
        spec_data = jsonutils.loads(data['spec'])
        self.assertEqual(u'os.nova.server', spec_data['type'])
        self.assertEqual(u'1.0', spec_data['version'])