def test_create_bay_with_invalid_ext_network(self, mock_valid_os_res): bdict = apiutils.bay_post_data() mock_valid_os_res.side_effect = exception.NetworkNotFound('test-net') response = self.post_json('/bays', bdict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertTrue(mock_valid_os_res.called) self.assertEqual(400, response.status_int)
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)
def validate_external_network(cli, external_network): """Validate external network""" networks = cli.neutron().list_networks() for net in networks.get('networks'): if (net.get('name') == external_network or net.get('id') == external_network): return raise exception.NetworkNotFound(network=external_network)
def test_replace_baymodel_with_no_exist_external_network_id(self): self.mock_valid_os_res.side_effect = exception.NetworkNotFound("aaa") response = self.patch_json('/baymodels/%s' % self.baymodel.uuid, [{'path': '/external_network_id', 'value': 'aaa', 'op': 'replace'}], expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_code) self.assertTrue(response.json['errors'])
def validate_external_network(cli, external_network): """Validate external network""" network_id = None networks = cli.neutron().list_networks() for net in networks.get('networks'): if (net.get('name') == external_network or net.get('id') == external_network): network_id = net.get('id') break if network_id is None: raise exception.NetworkNotFound(network=external_network)