Esempio n. 1
0
 def test_links(self):
     uuid = utils.generate_uuid()
     obj_utils.create_test_rc(self.context, id=1, uuid=uuid)
     response = self.get_json(
         '/rcs/%s/%s' % (uuid, '5d12f6fd-a196-4bf0-ae4c-1f639a523a52'))
     self.assertIn('links', response.keys())
     self.assertEqual(2, len(response['links']))
     self.assertIn(uuid, response['links'][0]['href'])
 def test_links(self):
     uuid = utils.generate_uuid()
     obj_utils.create_test_rc(self.context, id=1, uuid=uuid)
     response = self.get_json(
         '/rcs/%s/%s' % (uuid, '5d12f6fd-a196-4bf0-ae4c-1f639a523a52'))
     self.assertIn('links', response.keys())
     self.assertEqual(2, len(response['links']))
     self.assertIn(uuid, response['links'][0]['href'])
    def test_collection_links(self):
        for id_ in range(5):
            obj_utils.create_test_rc(self.context, id=id_,
                                     uuid=utils.generate_uuid())
        response = self.get_json('/rcs/?limit=3')
        self.assertEqual(3, len(response['rcs']))

        next_marker = response['rcs'][-1]['uuid']
        self.assertIn(next_marker, response['next'])
 def test_delete_multiple_rc_by_name(self):
     obj_utils.create_test_rc(self.context, name='test_rc',
                              uuid=utils.generate_uuid())
     obj_utils.create_test_rc(self.context, name='test_rc',
                              uuid=utils.generate_uuid())
     response = self.delete('/rcs/test_rc', expect_errors=True)
     self.assertEqual(409, response.status_int)
     self.assertEqual('application/json', response.content_type)
     self.assertTrue(response.json['error_message'])
 def test_links(self):
     uuid = utils.generate_uuid()
     obj_utils.create_test_rc(self.context, id=1, uuid=uuid)
     response = self.get_json('/rcs/%s' % uuid)
     self.assertIn('links', response.keys())
     self.assertEqual(2, len(response['links']))
     self.assertIn(uuid, response['links'][0]['href'])
     for l in response['links']:
         bookmark = l['rel'] == 'bookmark'
         self.assertTrue(self.validate_link(l['href'], bookmark=bookmark))
    def test_collection_links_default_limit(self):
        cfg.CONF.set_override('max_limit', 3, 'api')
        for id_ in range(5):
            obj_utils.create_test_rc(self.context, id=id_,
                                     uuid=utils.generate_uuid())
        response = self.get_json('/rcs')
        self.assertEqual(3, len(response['rcs']))

        next_marker = response['rcs'][-1]['uuid']
        self.assertIn(next_marker, response['next'])
 def test_links(self):
     uuid = utils.generate_uuid()
     obj_utils.create_test_rc(self.context, id=1, uuid=uuid)
     response = self.get_json('/rcs/%s' % uuid)
     self.assertIn('links', response.keys())
     self.assertEqual(2, len(response['links']))
     self.assertIn(uuid, response['links'][0]['href'])
     for l in response['links']:
         bookmark = l['rel'] == 'bookmark'
         self.assertTrue(self.validate_link(l['href'], bookmark=bookmark))
Esempio n. 8
0
    def test_collection_links(self):
        for id_ in range(5):
            obj_utils.create_test_rc(self.context,
                                     id=id_,
                                     uuid=utils.generate_uuid())
        response = self.get_json('/rcs/?limit=3')
        self.assertEqual(3, len(response['rcs']))

        next_marker = response['rcs'][-1]['uuid']
        self.assertIn(next_marker, response['next'])
Esempio n. 9
0
    def test_collection_links_default_limit(self):
        cfg.CONF.set_override('max_limit', 3, 'api')
        for id_ in range(5):
            obj_utils.create_test_rc(self.context,
                                     id=id_,
                                     uuid=utils.generate_uuid())
        response = self.get_json('/rcs')
        self.assertEqual(3, len(response['rcs']))

        next_marker = response['rcs'][-1]['uuid']
        self.assertIn(next_marker, response['next'])
Esempio n. 10
0
 def test_get_one_by_name_multiple_rc(self):
     obj_utils.create_test_rc(self.context,
                              name='test_rc',
                              uuid=utils.generate_uuid())
     obj_utils.create_test_rc(self.context,
                              name='test_rc',
                              uuid=utils.generate_uuid())
     response = self.get_json('/rcs/test_rc', expect_errors=True)
     self.assertEqual(409, response.status_int)
     self.assertEqual('application/json', response.content_type)
     self.assertTrue(response.json['error_message'])
 def test_get_one_by_name_multiple_rc(self):
     obj_utils.create_test_rc(
         self.context, name='test_rc',
         uuid=utils.generate_uuid())
     obj_utils.create_test_rc(
         self.context, name='test_rc',
         uuid=utils.generate_uuid())
     response = self.get_json(
         '/rcs/test_rc/5d12f6fd-a196-4bf0-ae4c-1f639a523a52',
         expect_errors=True)
     self.assertEqual(409, response.status_int)
     self.assertEqual('application/json', response.content_type)
     self.assertTrue(response.json['error_message'])
Esempio n. 12
0
 def test_delete_multiple_rc_by_name(self):
     obj_utils.create_test_rc(self.context,
                              name='test_rc',
                              uuid=utils.generate_uuid())
     obj_utils.create_test_rc(self.context,
                              name='test_rc',
                              uuid=utils.generate_uuid())
     response = self.delete(
         '/rcs/test_rc/5d12f6fd-a196-4bf0-ae4c-1f639a523a5',
         expect_errors=True)
     self.assertEqual(409, response.status_int)
     self.assertEqual('application/json', response.content_type)
     self.assertTrue(response.json['error_message'])
Esempio n. 13
0
 def test_delete_multiple_rc_by_name(self, mock_rc_delete):
     err = rest.ApiException(status=409)
     mock_rc_delete.side_effect = err
     obj_utils.create_test_rc(self.context, name='test_rc',
                              uuid=utils.generate_uuid())
     obj_utils.create_test_rc(self.context, name='test_rc',
                              uuid=utils.generate_uuid())
     response = self.delete(
         '/rcs/test_rc/5d12f6fd-a196-4bf0-ae4c-1f639a523a52',
         expect_errors=True)
     self.assertEqual(500, response.status_int)
     self.assertEqual('application/json', response.content_type)
     self.assertTrue(response.json['error_message'])
Esempio n. 14
0
 def test_get_one_by_name_multiple_rc(self, mock_rc_show):
     obj_utils.create_test_rc(
         self.context, name='test_rc',
         uuid=utils.generate_uuid())
     obj_utils.create_test_rc(
         self.context, name='test_rc',
         uuid=utils.generate_uuid())
     err = rest.ApiException(status=500)
     mock_rc_show.side_effect = err
     response = self.get_json(
         '/rcs/test_rc/5d12f6fd-a196-4bf0-ae4c-1f639a523a52',
         expect_errors=True)
     self.assertEqual(500, response.status_int)
     self.assertEqual('application/json', response.content_type)
     self.assertTrue(response.json['errors'])
Esempio n. 15
0
 def test_get_one_by_name_multiple_rc(self, mock_rc_show):
     obj_utils.create_test_rc(self.context,
                              name='test_rc',
                              uuid=utils.generate_uuid())
     obj_utils.create_test_rc(self.context,
                              name='test_rc',
                              uuid=utils.generate_uuid())
     err = rest.ApiException(status=500)
     mock_rc_show.side_effect = err
     response = self.get_json(
         '/rcs/test_rc/5d12f6fd-a196-4bf0-ae4c-1f639a523a52',
         expect_errors=True)
     self.assertEqual(500, response.status_int)
     self.assertEqual('application/json', response.content_type)
     self.assertTrue(response.json['errors'])
Esempio n. 16
0
 def setUp(self):
     super(TestPatch, self).setUp()
     obj_utils.create_test_bay(self.context)
     self.rc = obj_utils.create_test_rc(self.context,
                                        images=['rc_example_A_image'])
     self.another_bay = obj_utils.create_test_bay(
         self.context, uuid=utils.generate_uuid())
Esempio n. 17
0
 def test_detail(self, mock_rc_list):
     rc = obj_utils.create_test_rc(self.context)
     mock_rc_list.return_value = [rc]
     response = self.get_json('/rcs/detail?bay_ident=5d12f6fd-a196-4bf0-'
                              'ae4c-1f639a523a52')
     self.assertEqual(rc.uuid, response['rcs'][0]["uuid"])
     self._assert_rc_fields(response['rcs'][0])
Esempio n. 18
0
 def test_policy_disallow_delete(self):
     rc = obj_utils.create_test_rc(self.context,
                                   name='test_rc',
                                   uuid=utils.generate_uuid())
     self._common_policy_check(
         'rc:delete', self.delete,
         '/rcs/%s' % rc.uuid)
Esempio n. 19
0
 def test_collection_links(self, mock_rc_list):
     for id_ in range(5):
         rc = obj_utils.create_test_rc(self.context, id=id_,
                                       uuid=utils.generate_uuid())
     mock_rc_list.return_value = [rc]
     response = self.get_json('/rcs/?limit=1')
     self.assertEqual(1, len(response['rcs']))
Esempio n. 20
0
 def setUp(self):
     super(TestPatch, self).setUp()
     obj_utils.create_test_bay(self.context)
     self.rc = obj_utils.create_test_rc(self.context,
                                        images=['rc_example_A_image'])
     self.another_bay = obj_utils.create_test_bay(self.context,
                            uuid=utils.generate_uuid())
Esempio n. 21
0
 def test_collection_links_default_limit(self, mock_rc_list):
     cfg.CONF.set_override('max_limit', 3, 'api')
     for id_ in range(5):
         rc = obj_utils.create_test_rc(self.context, id=id_,
                                       uuid=utils.generate_uuid())
     mock_rc_list.return_value = [rc]
     response = self.get_json('/rcs')
     self.assertEqual(1, len(response['rcs']))
Esempio n. 22
0
 def test_collection_links(self, mock_rc_list):
     for id_ in range(5):
         rc = obj_utils.create_test_rc(self.context,
                                       id=id_,
                                       uuid=utils.generate_uuid())
     mock_rc_list.return_value = [rc]
     response = self.get_json('/rcs/?limit=1')
     self.assertEqual(1, len(response['rcs']))
Esempio n. 23
0
 def test_collection_links(self, mock_rc_list):
     for id_ in range(5):
         rc = obj_utils.create_test_rc(self.context, id=id_,
                                       uuid=utils.generate_uuid())
     mock_rc_list.return_value = [rc]
     response = self.get_json('/rcs/?limit=1&bay_ident=5d12f6fd-a196-4bf0'
                              '-ae4c-1f639a523a52')
     self.assertEqual(1, len(response['rcs']))
Esempio n. 24
0
 def setUp(self):
     super(TestDelete, self).setUp()
     obj_utils.create_test_bay(self.context)
     self.rc = obj_utils.create_test_rc(self.context)
     p = mock.patch.object(rpcapi.API, 'rc_delete')
     self.mock_rc_delete = p.start()
     self.mock_rc_delete.side_effect = self._simulate_rpc_rc_delete
     self.addCleanup(p.stop)
Esempio n. 25
0
 def test_policy_disallow_delete(self):
     rc = obj_utils.create_test_rc(self.context,
                                   name='test_rc',
                                   uuid=utils.generate_uuid())
     self._common_policy_check(
         'rc:delete', self.delete,
         '/rcs/%s/%s' % (rc.uuid, utils.generate_uuid()),
         expect_errors=True)
Esempio n. 26
0
 def test_links(self, mock_rc_show):
     uuid = utils.generate_uuid()
     rc = obj_utils.create_test_rc(self.context, id=1, uuid=uuid)
     mock_rc_show.return_value = rc
     response = self.get_json('/rcs/%s/%s' % (uuid, rc.bay_uuid))
     self.assertIn('links', response.keys())
     self.assertEqual(2, len(response['links']))
     self.assertIn(uuid, response['links'][0]['href'])
    def test_replace_ok_by_name_multiple_rc(self, mock_utcnow):
        new_image = 'rc_example_B_image'
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        mock_utcnow.return_value = test_time

        obj_utils.create_test_rc(self.context, name='test_rc',
                                 uuid=utils.generate_uuid())
        obj_utils.create_test_rc(self.context, name='test_rc',
                                 uuid=utils.generate_uuid())

        response = self.patch_json('/rcs/test_rc',
                                   [{'path': '/images/0',
                                     'value': new_image,
                                     'op': 'replace'}],
                                   expect_errors=True)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(409, response.status_code)
 def setUp(self):
     super(TestDelete, self).setUp()
     obj_utils.create_test_bay(self.context)
     self.rc = obj_utils.create_test_rc(self.context)
     p = mock.patch.object(rpcapi.API, 'rc_delete')
     self.mock_rc_delete = p.start()
     self.mock_rc_delete.side_effect = self._simulate_rpc_rc_delete
     self.addCleanup(p.stop)
Esempio n. 29
0
 def test_collection_links_default_limit(self, mock_rc_list):
     cfg.CONF.set_override('max_limit', 3, 'api')
     for id_ in range(5):
         rc = obj_utils.create_test_rc(self.context, id=id_,
                                       uuid=utils.generate_uuid())
     mock_rc_list.return_value = [rc]
     response = self.get_json('/rcs?bay_ident=5d12f6fd-a196-4bf0-ae4c-'
                              '1f639a523a52')
     self.assertEqual(1, len(response['rcs']))
Esempio n. 30
0
    def test_replace_ok_by_name_multiple_rc(self, mock_utcnow):
        new_image = 'rc_example_B_image'
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        mock_utcnow.return_value = test_time

        obj_utils.create_test_rc(self.context, name='test_rc',
                                 uuid=utils.generate_uuid())
        obj_utils.create_test_rc(self.context, name='test_rc',
                                 uuid=utils.generate_uuid())

        response = self.patch_json(
            '/rcs/test_rc/5d12f6fd-a196-4bf0-ae4c-1f639a523a52',
            [{'path': '/images/0',
              'value': new_image,
              'op': 'replace'}],
            expect_errors=True)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(400, response.status_code)
Esempio n. 31
0
    def test_policy_disallow_update(self):
        rc = obj_utils.create_test_rc(self.context,
                                      desc='test rc',
                                      uuid=utils.generate_uuid())

        new_image = 'rc_example_B_image'
        self._common_policy_check(
            'rc:update', self.patch_json,
            '/rcs/%s' % rc.uuid,
            [{'path': '/images/0', 'value': new_image, 'op': 'replace'}])
    def test_get_all_with_pagination_marker(self):
        rc_list = []
        for id_ in range(4):
            rc = obj_utils.create_test_rc(self.context, id=id_,
                                          uuid=utils.generate_uuid())
            rc_list.append(rc.uuid)

        response = self.get_json('/rcs?limit=3&marker=%s' % rc_list[2])
        self.assertEqual(1, len(response['rcs']))
        self.assertEqual(rc_list[-1], response['rcs'][0]['uuid'])
 def test_many(self):
     rc_list = []
     for id_ in range(5):
         rc = obj_utils.create_test_rc(self.context, id=id_,
                                       uuid=utils.generate_uuid())
         rc_list.append(rc.uuid)
     response = self.get_json('/rcs')
     self.assertEqual(len(rc_list), len(response['rcs']))
     uuids = [r['uuid'] for r in response['rcs']]
     self.assertEqual(sorted(rc_list), sorted(uuids))
Esempio n. 34
0
 def test_many(self):
     rc_list = []
     for id_ in range(5):
         rc = obj_utils.create_test_rc(self.context,
                                       id=id_,
                                       uuid=utils.generate_uuid())
         rc_list.append(rc.uuid)
     response = self.get_json('/rcs')
     self.assertEqual(len(rc_list), len(response['rcs']))
     uuids = [r['uuid'] for r in response['rcs']]
     self.assertEqual(sorted(rc_list), sorted(uuids))
Esempio n. 35
0
    def test_policy_disallow_update(self):
        rc = obj_utils.create_test_rc(self.context,
                                      desc='test rc',
                                      uuid=utils.generate_uuid())

        new_image = 'rc_example_B_image'
        self._common_policy_check(
            'rc:update', self.patch_json,
            '/rcs/%s/%s' % (rc.uuid, utils.generate_uuid()),
            [{'path': '/images/0', 'value': new_image, 'op': 'replace'}],
            expect_errors=True)
Esempio n. 36
0
    def test_get_all_with_pagination_marker(self):
        rc_list = []
        for id_ in range(4):
            rc = obj_utils.create_test_rc(self.context,
                                          id=id_,
                                          uuid=utils.generate_uuid())
            rc_list.append(rc.uuid)

        response = self.get_json('/rcs?limit=3&marker=%s' % rc_list[2])
        self.assertEqual(1, len(response['rcs']))
        self.assertEqual(rc_list[-1], response['rcs'][0]['uuid'])
Esempio n. 37
0
 def test_many(self, mock_rc_list):
     rc_list = []
     for id_ in range(1):
         rc = obj_utils.create_test_rc(self.context, id=id_,
                                       uuid=utils.generate_uuid())
         rc_list.append(rc.uuid)
     mock_rc_list.return_value = [rc]
     response = self.get_json('/rcs?bay_ident=5d12f6fd-a196-4bf0-ae4c-'
                              '1f639a523a52')
     self.assertEqual(len(rc_list), len(response['rcs']))
     uuids = [r['uuid'] for r in response['rcs']]
     self.assertEqual(sorted(rc_list), sorted(uuids))
Esempio n. 38
0
    def test_get_all_with_pagination_marker(self, mock_rc_list):
        rc_list = []
        for id_ in range(4):
            rc = obj_utils.create_test_rc(self.context, id=id_,
                                          uuid=utils.generate_uuid())
            rc_list.append(rc.uuid)

        mock_rc_list.return_value = [rc]
        response = self.get_json('/rcs?limit=3&marker=%s&bay_ident=5d12f6fd-'
                                 'a196-4bf0-ae4c-1f639a523a52' % rc_list[2])
        self.assertEqual(1, len(response['rcs']))
        self.assertEqual(rc_list[-1], response['rcs'][0]['uuid'])
Esempio n. 39
0
 def setUp(self):
     super(TestPost, self).setUp()
     self.test_bay = obj_utils.create_test_bay(self.context,
                                               coe='kubernetes')
     self.rc_obj = obj_utils.create_test_rc(self.context)
     p = mock.patch.object(rpcapi.API, 'rc_create')
     self.mock_rc_create = p.start()
     self.mock_rc_create.return_value = self.rc_obj
     self.addCleanup(p.stop)
     p = mock.patch('magnum.objects.BayModel.get_by_uuid')
     self.mock_baymodel_get_by_uuid = obj_utils.get_test_baymodel(
         self.context, uuid=self.test_bay.baymodel_id, coe='kubernetes')
Esempio n. 40
0
 def setUp(self):
     super(TestPost, self).setUp()
     obj_utils.create_test_bay(self.context)
     self.rc_obj = obj_utils.create_test_rc(self.context)
     p = mock.patch.object(rpcapi.API, 'rc_create')
     self.mock_rc_create = p.start()
     self.mock_rc_create.return_value = self.rc_obj
     self.addCleanup(p.stop)
     p = mock.patch('magnum.objects.BayModel.get_by_uuid')
     self.mock_baymodel_get_by_uuid = p.start()
     self.mock_baymodel_get_by_uuid.return_value.coe = 'kubernetes'
     self.addCleanup(p.stop)
Esempio n. 41
0
    def test_detail_with_pagination_marker(self, mock_rc_list):
        rc_list = []
        for id_ in range(4):
            rc = obj_utils.create_test_rc(self.context, id=id_,
                                          uuid=utils.generate_uuid())
            rc_list.append(rc.uuid)

        mock_rc_list.return_value = [rc]
        response = self.get_json('/rcs/detail?limit=3&marker=%s'
                                 % (rc_list[2]))

        self.assertEqual(1, len(response['rcs']))
        self.assertEqual(rc_list[-1], response['rcs'][0]['uuid'])
        self._assert_rc_fields(response['rcs'][0])
Esempio n. 42
0
    def test_detail_with_pagination_marker(self, mock_rc_list):
        rc_list = []
        for id_ in range(4):
            rc = obj_utils.create_test_rc(self.context,
                                          id=id_,
                                          uuid=utils.generate_uuid())
            rc_list.append(rc.uuid)

        mock_rc_list.return_value = [rc]
        response = self.get_json('/rcs/detail?limit=3&marker=%s' %
                                 (rc_list[2]))

        self.assertEqual(1, len(response['rcs']))
        self.assertEqual(rc_list[-1], response['rcs'][0]['uuid'])
        self._assert_rc_fields(response['rcs'][0])
Esempio n. 43
0
 def test_delete_bay_with_replication_controllers(self):
     obj_utils.create_test_rc(self.context, bay_uuid=self.bay.uuid)
     response = self.delete('/bays/%s' % self.bay.uuid,
                            expect_errors=True)
     self.assertEqual(204, response.status_int)
Esempio n. 44
0
 def test_delete_bay_with_replication_controllers(self):
     obj_utils.create_test_rc(self.context, bay_uuid=self.bay.uuid)
     response = self.delete('/bays/%s' % self.bay.uuid, expect_errors=True)
     self.assertEqual(204, response.status_int)
Esempio n. 45
0
 def test_one(self):
     rc = obj_utils.create_test_rc(self.context)
     response = self.get_json('/rcs')
     self.assertEqual(rc.uuid, response['rcs'][0]["uuid"])
     self._assert_rc_fields(response['rcs'][0])
Esempio n. 46
0
 def test_get_one_by_name(self, mock_rc_show):
     rc = obj_utils.create_test_rc(self.context)
     mock_rc_show.return_value = rc
     response = self.get_json('/rcs/%s/%s' % (rc['name'], rc['bay_uuid']))
     self.assertEqual(rc.uuid, response['uuid'])
     self._assert_rc_fields(response)
Esempio n. 47
0
 def test_get_one(self):
     rc = obj_utils.create_test_rc(self.context)
     response = self.get_json('/rcs/%s/%s' % (rc['uuid'], rc['bay_uuid']))
     self.assertEqual(rc.uuid, response['uuid'])
     self._assert_rc_fields(response)
 def test_get_one_by_name(self):
     rc = obj_utils.create_test_rc(self.context)
     response = self.get_json('/rcs/%s' % rc['name'])
     self.assertEqual(rc.uuid, response['uuid'])
     self._assert_rc_fields(response)
Esempio n. 49
0
 def setUp(self):
     super(TestDelete, self).setUp()
     obj_utils.create_test_bay(self.context, coe='kubernetes')
     self.rc = obj_utils.create_test_rc(self.context)
 def test_detail(self):
     rc = obj_utils.create_test_rc(self.context)
     response = self.get_json('/rcs/detail')
     self.assertEqual(rc.uuid, response['rcs'][0]["uuid"])
     self._assert_rc_fields(response['rcs'][0])
Esempio n. 51
0
 def test_detail_against_single(self):
     rc = obj_utils.create_test_rc(self.context)
     response = self.get_json('/rcs/%s/detail' % rc['uuid'],
                              expect_errors=True)
     self.assertEqual(404, response.status_int)