示例#1
0
    def test_create_baymodel_with_no_network_driver(self, mock_keypair_exists,
                                                    mock_image_data):
        mock_keypair_exists.return_value = None
        with mock.patch.object(self.dbapi,
                               'create_baymodel',
                               wraps=self.dbapi.create_baymodel) as cc_mock:
            mock_image_data.return_value = {
                'name': 'mock_name',
                'os_distro': 'fedora-atomic'
            }
            bdict = apiutils.baymodel_post_data()
            response = self.post_json('/baymodels', bdict)
            self.assertEqual(bdict['network_driver'],
                             response.json['network_driver'])
            cc_mock.assert_called_once_with(mock.ANY)
            self.assertNotIn('id', cc_mock.call_args[0][0])

        mock_image_data.return_value = {
            'name': 'mock_name',
            'os_distro': 'fedora-atomic'
        }
        bdict = apiutils.baymodel_post_data()
        del bdict['uuid']
        response = self.post_json('/baymodels', bdict)
        self.assertEqual(bdict['image_id'], response.json['image_id'])
        self.assertTrue(utils.is_uuid_like(response.json['uuid']))
示例#2
0
 def test_policy_disallow_create(self):
     bdict = apiutils.baymodel_post_data(name='bay_model_example_A')
     self._common_policy_check("baymodel:create",
                               self.post_json,
                               '/baymodels',
                               bdict,
                               expect_errors=True)
示例#3
0
 def test_create_baymodel_with_no_exist_image_name(self, mock_keypair_exists, mock_image_data):
     mock_keypair_exists.return_value = None
     mock_image_data.side_effect = exception.ResourceNotFound("test-img")
     bdict = apiutils.baymodel_post_data()
     del bdict["uuid"]
     response = self.post_json("/baymodels", bdict, expect_errors=True)
     self.assertEqual(404, response.status_int)
示例#4
0
 def _test_create_baymodel_network_driver_attr(self, baymodel_dict,
                                               baymodel_config_dict,
                                               expect_errors,
                                               mock_keypair_exists,
                                               mock_image_data):
     mock_keypair_exists.return_value = None
     mock_image_data.return_value = {
         'name': 'mock_name',
         'os_distro': 'fedora-atomic'
     }
     for k, v in baymodel_config_dict.items():
         cfg.CONF.set_override(k, v, 'baymodel')
     with mock.patch.object(self.dbapi,
                            'create_baymodel',
                            wraps=self.dbapi.create_baymodel) as cc_mock:
         bdict = apiutils.baymodel_post_data(**baymodel_dict)
         response = self.post_json('/baymodels',
                                   bdict,
                                   expect_errors=expect_errors)
         if expect_errors:
             self.assertEqual(400, response.status_int)
         else:
             expected_driver = bdict.get('network_driver')
             if not expected_driver:
                 expected_driver = (
                     cfg.CONF.baymodel.swarm_default_network_driver)
             self.assertEqual(expected_driver,
                              response.json['network_driver'])
             self.assertEqual(bdict['image_id'], response.json['image_id'])
             cc_mock.assert_called_once_with(mock.ANY)
             self.assertNotIn('id', cc_mock.call_args[0][0])
             self.assertTrue(utils.is_uuid_like(response.json['uuid']))
示例#5
0
 def test_create_baymodel_generate_uuid(self):
     cdict = apiutils.baymodel_post_data()
     del cdict['uuid']
     response = self.post_json('/baymodels', cdict)
     self.assertEqual(cdict['image_id'],
                      response.json['image_id'])
     self.assertTrue(utils.is_uuid_like(response.json['uuid']))
示例#6
0
 def test_create_baymodel_with_no_os_distro_image(self,
                                                  mock_image_data):
     mock_image_data.side_effect = exception.OSDistroFieldNotFound('img')
     bdict = apiutils.baymodel_post_data()
     del bdict['uuid']
     response = self.post_json('/baymodels', bdict, expect_errors=True)
     self.assertEqual(400, response.status_int)
示例#7
0
 def test_create_baymodel_with_no_exist_image_name(self,
                                                   mock_image_data):
     mock_image_data.side_effect = exception.ResourceNotFound('test-img')
     bdict = apiutils.baymodel_post_data()
     del bdict['uuid']
     response = self.post_json('/baymodels', bdict, expect_errors=True)
     self.assertEqual(404, response.status_int)
示例#8
0
 def test_create_baymodel_with_invalid_docker_volume_size(self):
     with mock.patch.object(self.dbapi,
                            'create_baymodel',
                            wraps=self.dbapi.create_baymodel) as cc_mock:
         cdict = apiutils.baymodel_post_data(docker_volume_size='docker')
         self.assertRaises(AppError, self.post_json, '/baymodels', cdict)
         self.assertFalse(cc_mock.called)
示例#9
0
 def test_create_baymodel_with_multi_image_name(self, mock_keypair_exists, mock_image_data):
     mock_keypair_exists.return_value = None
     mock_image_data.side_effect = exception.Conflict("Multiple images")
     bdict = apiutils.baymodel_post_data()
     del bdict["uuid"]
     response = self.post_json("/baymodels", bdict, expect_errors=True)
     self.assertEqual(409, response.status_int)
示例#10
0
 def test_create_baymodel_generate_uuid(self, mock_image_data):
     mock_image_data.return_value = {"name": "mock_name", "os_distro": "fedora-atomic"}
     bdict = apiutils.baymodel_post_data()
     del bdict["uuid"]
     response = self.post_json("/baymodels", bdict)
     self.assertEqual(bdict["image_id"], response.json["image_id"])
     self.assertTrue(utils.is_uuid_like(response.json["uuid"]))
示例#11
0
 def test_create_baymodel_with_dns(self, mock_keypair_exists, mock_image_data):
     mock_keypair_exists.return_value = None
     mock_image_data.return_value = {"name": "mock_name", "os_distro": "fedora-atomic"}
     bdict = apiutils.baymodel_post_data()
     response = self.post_json("/baymodels", bdict)
     self.assertEqual(201, response.status_int)
     self.assertEqual(bdict["dns_nameserver"], response.json["dns_nameserver"])
示例#12
0
 def test_create_baymodel_with_no_exist_image_name(self,
                                                   mock_image_data):
     mock_image_data.side_effect = exception.ResourceNotFound('test-img')
     bdict = apiutils.baymodel_post_data()
     del bdict['uuid']
     response = self.post_json('/baymodels', bdict, expect_errors=True)
     self.assertEqual(404, response.status_int)
示例#13
0
 def test_create_baymodel_with_os_distro_image(self, mock_keypair_exists, mock_image_data):
     mock_keypair_exists.return_value = None
     mock_image_data.return_value = {"name": "mock_name", "os_distro": "fedora-atomic"}
     bdict = apiutils.baymodel_post_data()
     del bdict["uuid"]
     response = self.post_json("/baymodels", bdict, expect_errors=True)
     self.assertEqual(201, response.status_int)
示例#14
0
 def test_create_baymodel_with_no_os_distro_image(self,
                                                  mock_image_data):
     mock_image_data.side_effect = exception.OSDistroFieldNotFound('img')
     bdict = apiutils.baymodel_post_data()
     del bdict['uuid']
     response = self.post_json('/baymodels', bdict, expect_errors=True)
     self.assertEqual(400, response.status_int)
示例#15
0
 def test_create_baymodel_with_multi_image_name(self,
                                                mock_image_data):
     mock_image_data.side_effect = exception.Conflict('Multiple images')
     bdict = apiutils.baymodel_post_data()
     del bdict['uuid']
     response = self.post_json('/baymodels', bdict, expect_errors=True)
     self.assertEqual(409, response.status_int)
示例#16
0
 def test_create_baymodel_with_os_distro_image(self, mock_image_data):
     mock_image_data.return_value = {'name': 'mock_name',
                                     'os_distro': 'fedora-atomic'}
     bdict = apiutils.baymodel_post_data()
     del bdict['uuid']
     response = self.post_json('/baymodels', bdict, expect_errors=True)
     self.assertEqual(201, response.status_int)
示例#17
0
 def _test_create_baymodel_network_driver_attr(self,
                                               baymodel_dict,
                                               baymodel_config_dict,
                                               expect_errors,
                                               mock_keypair_exists,
                                               mock_image_data):
     mock_keypair_exists.return_value = None
     mock_image_data.return_value = {'name': 'mock_name',
                                     'os_distro': 'fedora-atomic'}
     for k, v in baymodel_config_dict.items():
                 cfg.CONF.set_override(k, v, 'baymodel')
     with mock.patch.object(self.dbapi, 'create_baymodel',
                            wraps=self.dbapi.create_baymodel) as cc_mock:
         bdict = apiutils.baymodel_post_data(**baymodel_dict)
         response = self.post_json('/baymodels', bdict,
                                   expect_errors=expect_errors)
         if expect_errors:
             self.assertEqual(400, response.status_int)
         else:
             expected_driver = bdict.get('network_driver')
             if not expected_driver:
                 expected_driver = (
                     cfg.CONF.baymodel.swarm_default_network_driver)
             self.assertEqual(expected_driver,
                              response.json['network_driver'])
             self.assertEqual(bdict['image_id'],
                              response.json['image_id'])
             cc_mock.assert_called_once_with(mock.ANY)
             self.assertNotIn('id', cc_mock.call_args[0][0])
             self.assertTrue(utils.is_uuid_like(response.json['uuid']))
示例#18
0
 def test_create_baymodel_with_multi_image_name(self,
                                                mock_image_data):
     mock_image_data.side_effect = exception.Conflict('Multiple images')
     bdict = apiutils.baymodel_post_data()
     del bdict['uuid']
     response = self.post_json('/baymodels', bdict, expect_errors=True)
     self.assertEqual(409, response.status_int)
示例#19
0
 def test_create_baymodel_with_dns(self, mock_image_data):
     mock_image_data.return_value = {'name': 'mock_name',
                                     'os_distro': 'fedora-atomic'}
     bdict = apiutils.baymodel_post_data()
     response = self.post_json('/baymodels', bdict)
     self.assertEqual(201, response.status_int)
     self.assertEqual(bdict['dns_nameserver'],
                      response.json['dns_nameserver'])
示例#20
0
 def test_create_baymodel_public_fail(self, mock_policy, mock_keypair_exists, mock_image_data):
     with mock.patch.object(self.dbapi, "create_baymodel", wraps=self.dbapi.create_baymodel):
         mock_keypair_exists.return_value = None
         # make policy enforcement fail
         mock_policy.return_value = False
         mock_image_data.return_value = {"name": "mock_name", "os_distro": "fedora-atomic"}
         bdict = apiutils.baymodel_post_data(public=True)
         self.assertRaises(AppError, self.post_json, "/baymodels", bdict)
示例#21
0
 def test_create_baymodel_with_docker_volume_size(self, mock_image_data):
     with mock.patch.object(self.dbapi, "create_baymodel", wraps=self.dbapi.create_baymodel) as cc_mock:
         mock_image_data.return_value = {"name": "mock_name", "os_distro": "fedora-atomic"}
         bdict = apiutils.baymodel_post_data(docker_volume_size=99)
         response = self.post_json("/baymodels", bdict)
         self.assertEqual(bdict["docker_volume_size"], response.json["docker_volume_size"])
         cc_mock.assert_called_once_with(mock.ANY)
         self.assertNotIn("id", cc_mock.call_args[0][0])
示例#22
0
 def test_create_baymodel_with_no_exist_external_network(self,
                                                         mock_image_data):
     self.mock_valid_os_res.side_effect = exception.NetworkNotFound("test")
     mock_image_data.return_value = {'name': 'mock_name',
                                     'os_distro': 'fedora-atomic'}
     bdict = apiutils.baymodel_post_data()
     response = self.post_json('/baymodels', bdict, expect_errors=True)
     self.assertEqual(400, response.status_int)
示例#23
0
 def test_create_baymodel_with_os_distro_image(self,
                                               mock_image_data):
     mock_image_data.return_value = {'name': 'mock_name',
                                     'os_distro': 'fedora-atomic'}
     bdict = apiutils.baymodel_post_data()
     del bdict['uuid']
     response = self.post_json('/baymodels', bdict, expect_errors=True)
     self.assertEqual(201, response.status_int)
示例#24
0
 def test_create_baymodel_with_no_exist_external_network(self,
                                                         mock_image_data):
     self.mock_valid_os_res.side_effect = exception.NetworkNotFound("test")
     mock_image_data.return_value = {'name': 'mock_name',
                                     'os_distro': 'fedora-atomic'}
     bdict = apiutils.baymodel_post_data()
     response = self.post_json('/baymodels', bdict, expect_errors=True)
     self.assertEqual(400, response.status_int)
示例#25
0
 def test_create_baymodel_with_no_os_distro_image(self, mock_keypair_exists,
                                                  mock_image_data):
     mock_keypair_exists.return_value = None
     mock_image_data.return_value = {'name': 'mock_name'}
     bdict = apiutils.baymodel_post_data()
     del bdict['uuid']
     response = self.post_json('/baymodels', bdict, expect_errors=True)
     self.assertEqual(404, response.status_int)
示例#26
0
 def test_create_baymodel_with_no_exist_image_name(self, mock_glance_client):
     mock_images = []
     mock_glance = mock.MagicMock()
     mock_glance.images.list.return_value = mock_images
     mock_glance_client.return_value = mock_glance
     bdict = apiutils.baymodel_post_data()
     del bdict["uuid"]
     response = self.post_json("/baymodels", bdict, expect_errors=True)
     self.assertEqual(404, response.status_int)
 def test_create_baymodel_with_invalid_docker_volume_size(self,
                            mock_image_data):
     with mock.patch.object(self.dbapi, 'create_baymodel',
                            wraps=self.dbapi.create_baymodel) as cc_mock:
         mock_image_data.return_value = {'name': 'mock_name',
                                         'os_distro': 'fedora-atomic'}
         cdict = apiutils.baymodel_post_data(docker_volume_size='docker')
         self.assertRaises(AppError, self.post_json, '/baymodels', cdict)
         self.assertFalse(cc_mock.called)
示例#28
0
 def test_create_baymodel_set_project_id_and_user_id(self, mock_keypair_exists, mock_image_data):
     with mock.patch.object(self.dbapi, "create_baymodel", wraps=self.dbapi.create_baymodel) as cc_mock:
         mock_keypair_exists.return_value = None
         mock_image_data.return_value = {"name": "mock_name", "os_distro": "fedora-atomic"}
         bdict = apiutils.baymodel_post_data()
         self.post_json("/baymodels", bdict)
         cc_mock.assert_called_once_with(mock.ANY)
         self.assertEqual(self.context.project_id, cc_mock.call_args[0][0]["project_id"])
         self.assertEqual(self.context.user_id, cc_mock.call_args[0][0]["user_id"])
示例#29
0
 def _create_baymodel_raises_app_error(self, **kwargs):
     # Create mock for db and image data
     with mock.patch.object(self.dbapi, "create_baymodel", wraps=self.dbapi.create_baymodel) as cc_mock, mock.patch(
         "magnum.api.attr_validator.validate_image"
     ) as mock_image_data:
         mock_image_data.return_value = {"name": "mock_name", "os_distro": "fedora-atomic"}
         bdict = apiutils.baymodel_post_data(**kwargs)
         self.assertRaises(AppError, self.post_json, "/baymodels", bdict)
         self.assertFalse(cc_mock.called)
示例#30
0
 def test_create_baymodel_with_labels(self, mock_keypair_exists, mock_image_data):
     with mock.patch.object(self.dbapi, "create_baymodel", wraps=self.dbapi.create_baymodel) as cc_mock:
         mock_keypair_exists.return_value = None
         mock_image_data.return_value = {"name": "mock_name", "os_distro": "fedora-atomic"}
         bdict = apiutils.baymodel_post_data(labels={"key1": "val1", "key2": "val2"})
         response = self.post_json("/baymodels", bdict)
         self.assertEqual(bdict["labels"], response.json["labels"])
         cc_mock.assert_called_once_with(mock.ANY)
         self.assertNotIn("id", cc_mock.call_args[0][0])
示例#31
0
 def test_create_baymodel_generate_uuid(self, mock_image_data):
     mock_image_data.return_value = {'name': 'mock_name',
                                     'os_distro': 'fedora-atomic'}
     bdict = apiutils.baymodel_post_data()
     del bdict['uuid']
     response = self.post_json('/baymodels', bdict)
     self.assertEqual(bdict['image_id'],
                      response.json['image_id'])
     self.assertTrue(utils.is_uuid_like(response.json['uuid']))
示例#32
0
 def test_create_baymodel_with_no_exist_keypair(self,
                                                mock_keypair_exists,
                                                mock_image_data):
     mock_keypair_exists.side_effect = exception.KeyPairNotFound("Test")
     mock_image_data.return_value = {'name': 'mock_name',
                                     'os_distro': 'fedora-atomic'}
     bdict = apiutils.baymodel_post_data()
     response = self.post_json('/baymodels', bdict, expect_errors=True)
     self.assertEqual(404, response.status_int)
示例#33
0
 def test_create_baymodel_with_image_name(self, mock_glance_client):
     mock_images = [{'name': 'mock_name', 'os_distro': 'fedora-atomic'}]
     mock_glance = mock.MagicMock()
     mock_glance.images.list.return_value = mock_images
     mock_glance_client.return_value = mock_glance
     bdict = apiutils.baymodel_post_data()
     del bdict['uuid']
     response = self.post_json('/baymodels', bdict, expect_errors=True)
     self.assertEqual(201, response.status_int)
示例#34
0
 def test_create_baymodel_with_external_network(self,
                                                mock_image_data):
     mock_image_data.return_value = {'name': 'mock_name',
                                     'os_distro': 'fedora-atomic'}
     bdict = apiutils.baymodel_post_data()
     response = self.post_json('/baymodels', bdict)
     self.assertEqual(201, response.status_int)
     self.assertEqual(bdict['external_network_id'],
                      response.json['external_network_id'])
示例#35
0
 def test_create_baymodel_with_no_os_distro_image(self,
                                                  mock_keypair_exists,
                                                  mock_image_data):
     mock_keypair_exists.return_value = None
     mock_image_data.return_value = {'name': 'mock_name'}
     bdict = apiutils.baymodel_post_data()
     del bdict['uuid']
     response = self.post_json('/baymodels', bdict, expect_errors=True)
     self.assertEqual(404, response.status_int)
示例#36
0
 def test_create_baymodel_doesnt_contain_id(self):
     with mock.patch.object(self.dbapi, 'create_baymodel',
                            wraps=self.dbapi.create_baymodel) as cc_mock:
         cdict = apiutils.baymodel_post_data(image_id='my-image')
         response = self.post_json('/baymodels', cdict)
         self.assertEqual(cdict['image_id'], response.json['image_id'])
         cc_mock.assert_called_once_with(mock.ANY)
         # Check that 'id' is not in first arg of positional args
         self.assertNotIn('id', cc_mock.call_args[0][0])
示例#37
0
 def test_create_baymodel_with_docker_volume_size(self):
     with mock.patch.object(self.dbapi, 'create_baymodel',
                            wraps=self.dbapi.create_baymodel) as cc_mock:
         cdict = apiutils.baymodel_post_data(docker_volume_size=99)
         response = self.post_json('/baymodels', cdict)
         self.assertEqual(cdict['docker_volume_size'],
                 response.json['docker_volume_size'])
         cc_mock.assert_called_once_with(mock.ANY)
         self.assertNotIn('id', cc_mock.call_args[0][0])
示例#38
0
 def test_create_baymodel_doesnt_contain_id(self, mock_image_data):
     with mock.patch.object(self.dbapi, "create_baymodel", wraps=self.dbapi.create_baymodel) as cc_mock:
         mock_image_data.return_value = {"name": "mock_name", "os_distro": "fedora-atomic"}
         bdict = apiutils.baymodel_post_data(image_id="my-image")
         response = self.post_json("/baymodels", bdict)
         self.assertEqual(bdict["image_id"], response.json["image_id"])
         cc_mock.assert_called_once_with(mock.ANY)
         # Check that 'id' is not in first arg of positional args
         self.assertNotIn("id", cc_mock.call_args[0][0])
示例#39
0
 def test_create_baymodel_with_image_name(self, mock_glance_client):
     mock_images = [{"name": "mock_name", "os_distro": "fedora-atomic"}]
     mock_glance = mock.MagicMock()
     mock_glance.images.list.return_value = mock_images
     mock_glance_client.return_value = mock_glance
     bdict = apiutils.baymodel_post_data()
     del bdict["uuid"]
     response = self.post_json("/baymodels", bdict, expect_errors=True)
     self.assertEqual(201, response.status_int)
示例#40
0
 def test_create_baymodel_doesnt_contain_id(self):
     with mock.patch.object(self.dbapi,
                            'create_baymodel',
                            wraps=self.dbapi.create_baymodel) as cc_mock:
         cdict = apiutils.baymodel_post_data(image_id='my-image')
         response = self.post_json('/baymodels', cdict)
         self.assertEqual(cdict['image_id'], response.json['image_id'])
         cc_mock.assert_called_once_with(mock.ANY)
         # Check that 'id' is not in first arg of positional args
         self.assertNotIn('id', cc_mock.call_args[0][0])
示例#41
0
 def test_create_baymodel_with_docker_volume_size(self):
     with mock.patch.object(self.dbapi,
                            'create_baymodel',
                            wraps=self.dbapi.create_baymodel) as cc_mock:
         cdict = apiutils.baymodel_post_data(docker_volume_size=99)
         response = self.post_json('/baymodels', cdict)
         self.assertEqual(cdict['docker_volume_size'],
                          response.json['docker_volume_size'])
         cc_mock.assert_called_once_with(mock.ANY)
         self.assertNotIn('id', cc_mock.call_args[0][0])
示例#42
0
 def test_create_baymodel_with_no_exist_image_name(self,
                                                   mock_glance_client):
     mock_images = []
     mock_glance = mock.MagicMock()
     mock_glance.images.list.return_value = mock_images
     mock_glance_client.return_value = mock_glance
     bdict = apiutils.baymodel_post_data()
     del bdict['uuid']
     response = self.post_json('/baymodels', bdict, expect_errors=True)
     self.assertEqual(404, response.status_int)
示例#43
0
 def test_create_baymodel_public_fail(self, mock_policy,
                                      mock_image_data):
     with mock.patch.object(self.dbapi, 'create_baymodel',
                            wraps=self.dbapi.create_baymodel):
         # make policy enforcement fail
         mock_policy.return_value = False
         mock_image_data.return_value = {'name': 'mock_name',
                                         'os_distro': 'fedora-atomic'}
         bdict = apiutils.baymodel_post_data(public=True)
         self.assertRaises(AppError, self.post_json, '/baymodels', bdict)
示例#44
0
 def test_create_baymodel_public_fail(self, mock_policy,
                                      mock_image_data):
     with mock.patch.object(self.dbapi, 'create_baymodel',
                            wraps=self.dbapi.create_baymodel):
         # make policy enforcement fail
         mock_policy.return_value = False
         mock_image_data.return_value = {'name': 'mock_name',
                                         'os_distro': 'fedora-atomic'}
         bdict = apiutils.baymodel_post_data(public=True)
         self.assertRaises(AppError, self.post_json, '/baymodels', bdict)
示例#45
0
 def test_create_baymodel_without_name(self, mock_image_data):
     with mock.patch.object(self.dbapi, 'create_baymodel',
                            wraps=self.dbapi.create_baymodel):
         mock_image_data.return_value = {'name': 'mock_name',
                                         'os_distro': 'fedora-atomic'}
         bdict = apiutils.baymodel_post_data()
         bdict.pop('name')
         resp = self.post_json('/baymodels', bdict)
         self.assertEqual(201, resp.status_int)
         self.assertIsNotNone(resp.json['name'])
示例#46
0
 def test_create_baymodel_generate_uuid(self, mock_image_data):
     mock_image_data.return_value = {
         'name': 'mock_name',
         'os_distro': 'fedora-atomic'
     }
     bdict = apiutils.baymodel_post_data()
     del bdict['uuid']
     response = self.post_json('/baymodels', bdict)
     self.assertEqual(bdict['image_id'], response.json['image_id'])
     self.assertTrue(utils.is_uuid_like(response.json['uuid']))
示例#47
0
 def test_create_baymodel_with_image_name(self, mock_glance_client):
     mock_images = [{'name': 'mock_name',
                    'os_distro': 'fedora-atomic'}]
     mock_glance = mock.MagicMock()
     mock_glance.images.list.return_value = mock_images
     mock_glance_client.return_value = mock_glance
     bdict = apiutils.baymodel_post_data()
     del bdict['uuid']
     response = self.post_json('/baymodels', bdict, expect_errors=True)
     self.assertEqual(201, response.status_int)
示例#48
0
 def test_create_baymodel_with_no_exist_keypair(self, mock_keypair_exists,
                                                mock_image_data):
     mock_keypair_exists.side_effect = exception.KeyPairNotFound("Test")
     mock_image_data.return_value = {
         'name': 'mock_name',
         'os_distro': 'fedora-atomic'
     }
     bdict = apiutils.baymodel_post_data()
     response = self.post_json('/baymodels', bdict, expect_errors=True)
     self.assertEqual(404, response.status_int)
示例#49
0
 def _create_baymodel_raises_app_error(self, **kwargs):
     # Create mock for db and image data
     with mock.patch.object(self.dbapi, 'create_baymodel',
                            wraps=self.dbapi.create_baymodel) as cc_mock,\
         mock.patch('magnum.api.attr_validator.validate_image')\
             as mock_image_data:
         mock_image_data.return_value = {'name': 'mock_name',
                                         'os_distro': 'fedora-atomic'}
         bdict = apiutils.baymodel_post_data(**kwargs)
         self.assertRaises(AppError, self.post_json, '/baymodels', bdict)
         self.assertFalse(cc_mock.called)
示例#50
0
 def test_create_baymodel_with_no_exist_keypair(self, mock_image_data,
                                                mock_nova_client):
     mock_nova = mock.MagicMock()
     mock_nova.keypairs.get.side_effect = nova_exc.NotFound("Test")
     mock_nova_client.return_value = mock_nova
     mock_image_data.return_value = {
         'name': 'mock_name',
         'os_distro': 'fedora-atomic'
     }
     bdict = apiutils.baymodel_post_data()
     response = self.post_json('/baymodels', bdict, expect_errors=True)
     self.assertEqual(404, response.status_int)
示例#51
0
 def test_create_baymodel_doesnt_contain_id(self,
                                            mock_image_data):
     with mock.patch.object(self.dbapi, 'create_baymodel',
                            wraps=self.dbapi.create_baymodel) as cc_mock:
         mock_image_data.return_value = {'name': 'mock_name',
                                         'os_distro': 'fedora-atomic'}
         bdict = apiutils.baymodel_post_data(image_id='my-image')
         response = self.post_json('/baymodels', bdict)
         self.assertEqual(bdict['image_id'], response.json['image_id'])
         cc_mock.assert_called_once_with(mock.ANY)
         # Check that 'id' is not in first arg of positional args
         self.assertNotIn('id', cc_mock.call_args[0][0])
示例#52
0
 def test_create_baymodel_with_no_volume_driver(self,
                                                mock_image_data):
     with mock.patch.object(self.dbapi, 'create_baymodel',
                            wraps=self.dbapi.create_baymodel) as cc_mock:
         mock_image_data.return_value = {'name': 'mock_name',
                                         'os_distro': 'fedora-atomic'}
         bdict = apiutils.baymodel_post_data()
         response = self.post_json('/baymodels', bdict)
         self.assertEqual(bdict['volume_driver'],
                          response.json['volume_driver'])
         cc_mock.assert_called_once_with(mock.ANY)
         self.assertNotIn('id', cc_mock.call_args[0][0])
示例#53
0
 def test_create_baymodel_with_dns(self, mock_keypair_exists,
                                   mock_image_data):
     mock_keypair_exists.return_value = None
     mock_image_data.return_value = {
         'name': 'mock_name',
         'os_distro': 'fedora-atomic'
     }
     bdict = apiutils.baymodel_post_data()
     response = self.post_json('/baymodels', bdict)
     self.assertEqual(201, response.status_int)
     self.assertEqual(bdict['dns_nameserver'],
                      response.json['dns_nameserver'])
示例#54
0
 def test_create_baymodel_set_project_id_and_user_id(self,
                                                     mock_image_data):
     with mock.patch.object(self.dbapi, 'create_baymodel',
                            wraps=self.dbapi.create_baymodel) as cc_mock:
         mock_image_data.return_value = {'name': 'mock_name',
                                         'os_distro': 'fedora-atomic'}
         bdict = apiutils.baymodel_post_data()
         self.post_json('/baymodels', bdict)
         cc_mock.assert_called_once_with(mock.ANY)
         self.assertEqual(self.context.project_id,
                          cc_mock.call_args[0][0]['project_id'])
         self.assertEqual(self.context.user_id,
                          cc_mock.call_args[0][0]['user_id'])
示例#55
0
 def test_create_baymodel_public_not_set(self, mock_policy,
                                         mock_image_data):
     with mock.patch.object(self.dbapi, 'create_baymodel',
                            wraps=self.dbapi.create_baymodel) as cc_mock:
         mock_image_data.return_value = {'name': 'mock_name',
                                         'os_distro': 'fedora-atomic'}
         bdict = apiutils.baymodel_post_data(public=False)
         response = self.post_json('/baymodels', bdict)
         self.assertFalse(response.json['public'])
         # policy enforcement is called only once for enforce_wsgi
         self.assertEqual(1, mock_policy.call_count)
         cc_mock.assert_called_once_with(mock.ANY)
         self.assertNotIn('id', cc_mock.call_args[0][0])
         self.assertFalse(cc_mock.call_args[0][0]['public'])
示例#56
0
 def test_create_baymodel_public_success(self, mock_policy,
                                         mock_image_data):
     with mock.patch.object(self.dbapi, 'create_baymodel',
                            wraps=self.dbapi.create_baymodel) as cc_mock:
         mock_policy.return_value = True
         mock_image_data.return_value = {'name': 'mock_name',
                                         'os_distro': 'fedora-atomic'}
         bdict = apiutils.baymodel_post_data(public=True)
         response = self.post_json('/baymodels', bdict)
         self.assertTrue(response.json['public'])
         mock_policy.assert_called_with(mock.ANY, "baymodel:publish",
                                        None, do_raise=False)
         cc_mock.assert_called_once_with(mock.ANY)
         self.assertNotIn('id', cc_mock.call_args[0][0])
         self.assertTrue(cc_mock.call_args[0][0]['public'])
示例#57
0
    def test_create_baymodel(self, mock_utcnow):
        cdict = apiutils.baymodel_post_data()
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        mock_utcnow.return_value = test_time

        response = self.post_json('/baymodels', cdict)
        self.assertEqual(201, response.status_int)
        # Check location header
        self.assertIsNotNone(response.location)
        expected_location = '/v1/baymodels/%s' % cdict['uuid']
        self.assertEqual(
            urlparse.urlparse(response.location).path, expected_location)
        self.assertEqual(cdict['uuid'], response.json['uuid'])
        self.assertNotIn('updated_at', response.json.keys)
        return_created_at = timeutils.parse_isotime(
            response.json['created_at']).replace(tzinfo=None)
        self.assertEqual(test_time, return_created_at)
示例#58
0
 def test_create_baymodel_with_labels(self, mock_keypair_exists,
                                      mock_image_data):
     with mock.patch.object(self.dbapi,
                            'create_baymodel',
                            wraps=self.dbapi.create_baymodel) as cc_mock:
         mock_keypair_exists.return_value = None
         mock_image_data.return_value = {
             'name': 'mock_name',
             'os_distro': 'fedora-atomic'
         }
         bdict = apiutils.baymodel_post_data(labels={
             'key1': 'val1',
             'key2': 'val2'
         })
         response = self.post_json('/baymodels', bdict)
         self.assertEqual(bdict['labels'], response.json['labels'])
         cc_mock.assert_called_once_with(mock.ANY)
         self.assertNotIn('id', cc_mock.call_args[0][0])
示例#59
0
    def test_create_baymodel(self, mock_utcnow,
                             mock_image_data):
        bdict = apiutils.baymodel_post_data()
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        mock_utcnow.return_value = test_time
        mock_image_data.return_value = {'name': 'mock_name',
                                        'os_distro': 'fedora-atomic'}

        response = self.post_json('/baymodels', bdict)
        self.assertEqual(201, response.status_int)
        # Check location header
        self.assertIsNotNone(response.location)
        expected_location = '/v1/baymodels/%s' % bdict['uuid']
        self.assertEqual(expected_location,
                         urlparse.urlparse(response.location).path)
        self.assertEqual(bdict['uuid'], response.json['uuid'])
        self.assertNotIn('updated_at', response.json.keys)
        return_created_at = timeutils.parse_isotime(
            response.json['created_at']).replace(tzinfo=None)
        self.assertEqual(test_time, return_created_at)
示例#60
0
 def test_create_baymodel_without_keypair_id(self):
     bdict = apiutils.baymodel_post_data()
     del bdict['keypair_id']
     response = self.post_json('/baymodels', bdict, expect_errors=True)
     self.assertEqual(400, response.status_int)