コード例 #1
0
 def test_detail_using_query_false_and_fields(self):
     obj_utils.create_test_deploy_template(self.context)
     data = self.get_json(
         '/deploy_templates?detail=False&fields=steps',
         headers=self.headers)
     self.assertIn('steps', data['deploy_templates'][0])
     self.assertNotIn('uuid', data['deploy_templates'][0])
     self.assertNotIn('extra', data['deploy_templates'][0])
コード例 #2
0
 def test_links(self):
     uuid = uuidutils.generate_uuid()
     obj_utils.create_test_deploy_template(self.context, uuid=uuid)
     data = self.get_json('/deploy_templates/%s' % uuid,
                          headers=self.headers)
     self.assertIn('links', data)
     self.assertEqual(2, len(data['links']))
     self.assertIn(uuid, data['links'][0]['href'])
     for l in data['links']:
         bookmark = l['rel'] == 'bookmark'
         self.assertTrue(self.validate_link(l['href'], bookmark=bookmark,
                         headers=self.headers))
コード例 #3
0
 def test_get_one_invalid_api_version(self):
     template = obj_utils.create_test_deploy_template(self.context)
     response = self.get_json(
         '/deploy_templates/%s' % (template.uuid),
         headers=self.invalid_version_headers,
         expect_errors=True)
     self.assertEqual(http_client.NOT_FOUND, response.status_int)
コード例 #4
0
    def test_get_collection_custom_fields(self):
        fields = 'uuid,steps'
        for i in range(3):
            obj_utils.create_test_deploy_template(
                self.context,
                uuid=uuidutils.generate_uuid(),
                name='CUSTOM_DT%s' % i)

        data = self.get_json(
            '/deploy_templates?fields=%s' % fields,
            headers=self.headers)

        self.assertEqual(3, len(data['deploy_templates']))
        for template in data['deploy_templates']:
            # We always append "links"
            self.assertItemsEqual(['uuid', 'steps', 'links'], template)
コード例 #5
0
    def test_replace_multi(self, mock_save):
        steps = [
            {
                'interface': 'raid',
                'step': 'create_configuration%d' % i,
                'args': {},
                'priority': 10,
            }
            for i in range(3)
        ]
        template = obj_utils.create_test_deploy_template(
            self.context, uuid=uuidutils.generate_uuid(), name='CUSTOM_DT2',
            steps=steps)

        # mutate steps so we replace all of them
        for step in steps:
            step['priority'] = step['priority'] + 1

        patch = []
        for i, step in enumerate(steps):
            patch.append({'path': '/steps/%s' % i,
                          'value': step,
                          'op': 'replace'})
        response = self.patch_json('/deploy_templates/%s' % template.uuid,
                                   patch, headers=self.headers)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(http_client.OK, response.status_code)
        self.assertEqual(steps, response.json['steps'])
        mock_save.assert_called_once_with(mock.ANY)
コード例 #6
0
 def test_one(self):
     template = obj_utils.create_test_deploy_template(self.context)
     data = self.get_json('/deploy_templates', headers=self.headers)
     self.assertEqual(1, len(data['deploy_templates']))
     self.assertEqual(template.uuid, data['deploy_templates'][0]['uuid'])
     self.assertEqual(template.name, data['deploy_templates'][0]['name'])
     self.assertNotIn('steps', data['deploy_templates'][0])
     self.assertNotIn('extra', data['deploy_templates'][0])
コード例 #7
0
 def test_detail_query(self):
     template = obj_utils.create_test_deploy_template(self.context)
     data = self.get_json('/deploy_templates?detail=True',
                          headers=self.headers)
     self.assertEqual(template.uuid, data['deploy_templates'][0]['uuid'])
     self.assertIn('name', data['deploy_templates'][0])
     self.assertIn('steps', data['deploy_templates'][0])
     self.assertIn('extra', data['deploy_templates'][0])
コード例 #8
0
 def test_get_one_custom_fields(self):
     template = obj_utils.create_test_deploy_template(self.context)
     fields = 'name,steps'
     data = self.get_json(
         '/deploy_templates/%s?fields=%s' % (template.uuid, fields),
         headers=self.headers)
     # We always append "links"
     self.assertItemsEqual(['name', 'steps', 'links'], data)
コード例 #9
0
 def test_get_custom_fields_invalid_fields(self):
     template = obj_utils.create_test_deploy_template(self.context)
     fields = 'uuid,spongebob'
     response = self.get_json(
         '/deploy_templates/%s?fields=%s' % (template.uuid, fields),
         headers=self.headers, expect_errors=True)
     self.assertEqual(http_client.BAD_REQUEST, response.status_int)
     self.assertEqual('application/json', response.content_type)
     self.assertIn('spongebob', response.json['error_message'])
コード例 #10
0
    def test_many(self):
        templates = []
        for id_ in range(5):
            template = obj_utils.create_test_deploy_template(
                self.context, uuid=uuidutils.generate_uuid(),
                name='CUSTOM_DT%s' % id_)
            templates.append(template.uuid)
        data = self.get_json('/deploy_templates', headers=self.headers)
        self.assertEqual(len(templates), len(data['deploy_templates']))

        uuids = [n['uuid'] for n in data['deploy_templates']]
        six.assertCountEqual(self, templates, uuids)
コード例 #11
0
 def test_get_one(self):
     template = obj_utils.create_test_deploy_template(self.context)
     data = self.get_json('/deploy_templates/%s' % template.uuid,
                          headers=self.headers)
     self.assertEqual(template.uuid, data['uuid'])
     self.assertEqual(template.name, data['name'])
     self.assertEqual(template.extra, data['extra'])
     for t_dict_step, t_step in zip(data['steps'], template.steps):
         self.assertEqual(t_dict_step['interface'], t_step['interface'])
         self.assertEqual(t_dict_step['step'], t_step['step'])
         self.assertEqual(t_dict_step['args'], t_step['args'])
         self.assertEqual(t_dict_step['priority'], t_step['priority'])
コード例 #12
0
 def test_sort_key(self):
     templates = []
     for id_ in range(3):
         template = obj_utils.create_test_deploy_template(
             self.context,
             uuid=uuidutils.generate_uuid(),
             name='CUSTOM_DT%s' % id_)
         templates.append(template.uuid)
     data = self.get_json('/deploy_templates?sort_key=uuid',
                          headers=self.headers)
     uuids = [n['uuid'] for n in data['deploy_templates']]
     self.assertEqual(sorted(templates), uuids)
コード例 #13
0
    def test_collection_links_default_limit(self):
        cfg.CONF.set_override('max_limit', 3, 'api')
        templates = []
        for id_ in range(5):
            template = obj_utils.create_test_deploy_template(
                self.context, uuid=uuidutils.generate_uuid(),
                name='CUSTOM_DT%s' % id_)
            templates.append(template.uuid)
        data = self.get_json('/deploy_templates', headers=self.headers)
        self.assertEqual(3, len(data['deploy_templates']))

        next_marker = data['deploy_templates'][-1]['uuid']
        self.assertIn(next_marker, data['next'])
コード例 #14
0
 def _test_sort_key_allowed(self, detail=False):
     template_uuids = []
     for id_ in range(3, 0, -1):
         template = obj_utils.create_test_deploy_template(
             self.context,
             uuid=uuidutils.generate_uuid(),
             name='CUSTOM_DT%s' % id_)
         template_uuids.append(template.uuid)
     template_uuids.reverse()
     url = '/deploy_templates?sort_key=name&detail=%s' % str(detail)
     data = self.get_json(url, headers=self.headers)
     data_uuids = [p['uuid'] for p in data['deploy_templates']]
     self.assertEqual(template_uuids, data_uuids)
コード例 #15
0
 def test_replace_name_already_exist(self, mock_notify, mock_save):
     name = 'CUSTOM_DT2'
     obj_utils.create_test_deploy_template(self.context,
                                           uuid=uuidutils.generate_uuid(),
                                           name=name)
     mock_save.side_effect = exception.DeployTemplateAlreadyExists(
         uuid=self.template.uuid)
     response = self.patch_json('/deploy_templates/%s' % self.template.uuid,
                                [{'path': '/name',
                                  'value': name,
                                  'op': 'replace'}],
                                expect_errors=True,
                                headers=self.headers)
     self.assertEqual('application/json', response.content_type)
     self.assertEqual(http_client.CONFLICT, response.status_code)
     self.assertTrue(response.json['error_message'])
     mock_save.assert_called_once_with(mock.ANY)
     mock_notify.assert_has_calls([mock.call(mock.ANY, mock.ANY, 'update',
                                   obj_fields.NotificationLevel.INFO,
                                   obj_fields.NotificationStatus.START),
                                   mock.call(mock.ANY, mock.ANY, 'update',
                                   obj_fields.NotificationLevel.ERROR,
                                   obj_fields.NotificationStatus.ERROR)])
コード例 #16
0
    def test_get_collection_pagination_no_uuid(self):
        fields = 'name'
        limit = 2
        templates = []
        for id_ in range(3):
            template = obj_utils.create_test_deploy_template(
                self.context,
                uuid=uuidutils.generate_uuid(),
                name='CUSTOM_DT%s' % id_)
            templates.append(template)

        data = self.get_json(
            '/deploy_templates?fields=%s&limit=%s' % (fields, limit),
            headers=self.headers)

        self.assertEqual(limit, len(data['deploy_templates']))
        self.assertIn('marker=%s' % templates[limit - 1].uuid, data['next'])
コード例 #17
0
    def test_remove_multi(self, mock_save):
        steps = [
            {
                'interface': 'raid',
                'step': 'create_configuration%d' % i,
                'args': {},
                'priority': 10,
            }
            for i in range(3)
        ]
        template = obj_utils.create_test_deploy_template(
            self.context, uuid=uuidutils.generate_uuid(), name='CUSTOM_DT2',
            steps=steps)

        # Removing one step from the collection
        steps.pop(1)
        response = self.patch_json('/deploy_templates/%s' % template.uuid,
                                   [{'path': '/steps/1',
                                     'op': 'remove'}],
                                   headers=self.headers)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(http_client.OK, response.status_code)
        self.assertEqual(steps, response.json['steps'])
        mock_save.assert_called_once_with(mock.ANY)
コード例 #18
0
 def test_detail_query_false(self):
     obj_utils.create_test_deploy_template(self.context)
     data1 = self.get_json('/deploy_templates', headers=self.headers)
     data2 = self.get_json(
         '/deploy_templates?detail=False', headers=self.headers)
     self.assertEqual(data1['deploy_templates'], data2['deploy_templates'])
コード例 #19
0
 def test_get_all_invalid_api_version(self):
     obj_utils.create_test_deploy_template(self.context)
     response = self.get_json('/deploy_templates',
                              headers=self.invalid_version_headers,
                              expect_errors=True)
     self.assertEqual(http_client.NOT_FOUND, response.status_int)
コード例 #20
0
 def test_get_one_with_suffix(self):
     template = obj_utils.create_test_deploy_template(self.context,
                                                      name='CUSTOM_DT1')
     data = self.get_json('/deploy_templates/%s' % template.uuid,
                          headers=self.headers)
     self.assertEqual(template.uuid, data['uuid'])
コード例 #21
0
 def test_get_one_with_json(self):
     template = obj_utils.create_test_deploy_template(self.context)
     data = self.get_json('/deploy_templates/%s.json' % template.uuid,
                          headers=self.headers)
     self.assertEqual(template.uuid, data['uuid'])
コード例 #22
0
 def setUp(self):
     super(TestDelete, self).setUp()
     self.template = obj_utils.create_test_deploy_template(self.context)
コード例 #23
0
 def setUp(self):
     super(TestDelete, self).setUp()
     self.template = obj_utils.create_test_deploy_template(self.context)
コード例 #24
0
 def test_detail_query_false(self):
     obj_utils.create_test_deploy_template(self.context)
     data1 = self.get_json('/deploy_templates', headers=self.headers)
     data2 = self.get_json(
         '/deploy_templates?detail=False', headers=self.headers)
     self.assertEqual(data1['deploy_templates'], data2['deploy_templates'])
コード例 #25
0
 def test_detail_using_query_and_fields(self):
     obj_utils.create_test_deploy_template(self.context)
     response = self.get_json(
         '/deploy_templates?detail=True&fields=name', headers=self.headers,
         expect_errors=True)
     self.assertEqual(http_client.BAD_REQUEST, response.status_int)
コード例 #26
0
 def setUp(self):
     super(TestPatch, self).setUp()
     self.template = obj_utils.create_test_deploy_template(
         self.context, name='CUSTOM_DT1')
コード例 #27
0
 def test_get_one_with_suffix(self):
     template = obj_utils.create_test_deploy_template(self.context,
                                                      name='CUSTOM_DT1')
     data = self.get_json('/deploy_templates/%s' % template.uuid,
                          headers=self.headers)
     self.assertEqual(template.uuid, data['uuid'])
コード例 #28
0
 def test_detail_using_query_and_fields(self):
     obj_utils.create_test_deploy_template(self.context)
     response = self.get_json(
         '/deploy_templates?detail=True&fields=name', headers=self.headers,
         expect_errors=True)
     self.assertEqual(http_client.BAD_REQUEST, response.status_int)
コード例 #29
0
 def setUp(self):
     super(TestPatch, self).setUp()
     self.template = obj_utils.create_test_deploy_template(
         self.context, name='CUSTOM_DT1')
コード例 #30
0
 def test_get_one_with_json(self):
     template = obj_utils.create_test_deploy_template(self.context)
     data = self.get_json('/deploy_templates/%s.json' % template.uuid,
                          headers=self.headers)
     self.assertEqual(template.uuid, data['uuid'])