Merge "Use neutronclient to get networks."
This commit is contained in:
commit
fd5ad7f112
@ -17,6 +17,7 @@ import six
|
||||
|
||||
from oslo_log import log as logging
|
||||
|
||||
from neutronclient.common import exceptions as neutron_exceptions
|
||||
from novaclient import exceptions as nova_exceptions
|
||||
from trove.cluster.tasks import ClusterTask
|
||||
from trove.cluster.tasks import ClusterTasks
|
||||
@ -666,7 +667,7 @@ def validate_instance_nics(context, instances):
|
||||
return
|
||||
instance_nic = instance_nics[0]
|
||||
try:
|
||||
nova_client = remote.create_nova_client(context)
|
||||
nova_client.networks.get(instance_nic)
|
||||
except nova_exceptions.NotFound:
|
||||
neutron_client = remote.create_neutron_client(context)
|
||||
neutron_client.find_resource('network', instance_nic)
|
||||
except neutron_exceptions.NotFound:
|
||||
raise exception.NetworkNotFound(uuid=instance_nic)
|
||||
|
@ -201,13 +201,15 @@ class ClusterTest(trove_testtools.TestCase):
|
||||
@patch.object(task_api, 'load')
|
||||
@patch.object(QUOTAS, 'check_quotas')
|
||||
@patch.object(remote, 'create_nova_client')
|
||||
def test_create(self, mock_client, mock_check_quotas, mock_task_api,
|
||||
mock_db_create, mock_ins_create, mock_find_all):
|
||||
@patch.object(remote, 'create_neutron_client')
|
||||
def test_create(self, mock_neutron_client, mock_nova_client,
|
||||
mock_check_quotas, mock_task_api, mock_db_create,
|
||||
mock_ins_create, mock_find_all):
|
||||
instances = self.instances
|
||||
flavors = Mock()
|
||||
networks = Mock()
|
||||
mock_client.return_value.flavors = flavors
|
||||
mock_client.return_value.networks = networks
|
||||
mock_nova_client.return_value.flavors = flavors
|
||||
mock_neutron_client.return_value.find_resource = networks
|
||||
self.cluster.create(Mock(),
|
||||
self.cluster_name,
|
||||
self.datastore,
|
||||
@ -311,9 +313,12 @@ class ClusterTest(trove_testtools.TestCase):
|
||||
@patch.object(task_api, 'load')
|
||||
@patch.object(QUOTAS, 'check_quotas')
|
||||
@patch.object(remote, 'create_nova_client')
|
||||
def test_grow(self, mock_client, mock_check_quotas, mock_task_api,
|
||||
@patch.object(remote, 'create_neutron_client')
|
||||
def test_grow(self, mock_neutron_client, mock_nova_client,
|
||||
mock_check_quotas, mock_task_api,
|
||||
mock_inst_create, mock_conf, mock_update):
|
||||
mock_client.return_value.flavors = Mock()
|
||||
mock_nova_client.return_value.flavors = Mock()
|
||||
mock_neutron_client.return_value.find_resource = Mock()
|
||||
self.cluster.grow(self.instances)
|
||||
mock_update.assert_called_with(
|
||||
task_status=ClusterTasks.GROWING_CLUSTER)
|
||||
@ -327,9 +332,12 @@ class ClusterTest(trove_testtools.TestCase):
|
||||
@patch.object(inst_models.Instance, 'create')
|
||||
@patch.object(QUOTAS, 'check_quotas')
|
||||
@patch.object(remote, 'create_nova_client')
|
||||
def test_grow_exception(self, mock_client, mock_check_quotas,
|
||||
mock_inst_create, mock_conf, mock_update):
|
||||
mock_client.return_value.flavors = Mock()
|
||||
@patch.object(remote, 'create_neutron_client')
|
||||
def test_grow_exception(self, mock_neutron_client, mock_nova_client,
|
||||
mock_check_quotas, mock_inst_create,
|
||||
mock_conf, mock_update):
|
||||
mock_nova_client.return_value.flavors = Mock()
|
||||
mock_neutron_client.return_value.find_resource = Mock()
|
||||
with patch.object(task_api, 'load') as mock_load:
|
||||
mock_load.return_value.grow_cluster = Mock(
|
||||
side_effect=exception.BadRequest)
|
||||
|
@ -21,7 +21,7 @@ from mock import Mock
|
||||
from mock import patch
|
||||
from mock import PropertyMock
|
||||
|
||||
from novaclient import exceptions as nova_exceptions
|
||||
from neutronclient.common import exceptions as neutron_exceptions
|
||||
|
||||
from trove.cluster import models
|
||||
from trove.common import exception
|
||||
@ -173,8 +173,8 @@ class TestModels(trove_testtools.TestCase):
|
||||
assert_same_instance_volumes.assert_called_once_with(
|
||||
test_instances, required_size=required_volume_size)
|
||||
|
||||
@patch.object(remote, 'create_nova_client', return_value=MagicMock())
|
||||
def test_validate_instance_nics(self, create_nova_cli_mock):
|
||||
@patch.object(remote, 'create_neutron_client', return_value=MagicMock())
|
||||
def test_validate_instance_nics(self, create_neutron_cli_mock):
|
||||
|
||||
test_instances = [
|
||||
{'volume_size': 1, 'flavor_id': '1234',
|
||||
@ -197,9 +197,9 @@ class TestModels(trove_testtools.TestCase):
|
||||
{'volume_size': 1, 'flavor_id': '1234',
|
||||
'nics': [{"net-id": "foo-bar"}]}]
|
||||
|
||||
create_nova_cli_mock.return_value.networks.get = Mock(
|
||||
side_effect=nova_exceptions.NotFound(
|
||||
404, "Nic id not found %s" % id))
|
||||
create_neutron_cli_mock.return_value.find_resource = Mock(
|
||||
side_effect=neutron_exceptions.NotFound(
|
||||
"Nic id not found %s" % id))
|
||||
|
||||
self.assertRaises(exception.NetworkNotFound,
|
||||
models.validate_instance_nics,
|
||||
|
@ -195,11 +195,15 @@ class MongoDBClusterTest(trove_testtools.TestCase):
|
||||
@mock.patch.object(models.DBCluster, 'create')
|
||||
@mock.patch.object(QUOTAS, 'check_quotas')
|
||||
@mock.patch.object(remote, 'create_nova_client')
|
||||
def test_create(self, mock_client, mock_check_quotas,
|
||||
mock_db_create, mock_ins_create, mock_task_api):
|
||||
@mock.patch.object(remote, 'create_neutron_client')
|
||||
def test_create(self, mock_neutron_client, mock_nova_client,
|
||||
mock_check_quotas, mock_db_create,
|
||||
mock_ins_create, mock_task_api):
|
||||
instances = self.instances
|
||||
flavors = mock.Mock()
|
||||
mock_client.return_value.flavors = flavors
|
||||
networks = mock.Mock()
|
||||
mock_neutron_client.return_value.find_resource = networks
|
||||
mock_nova_client.return_value.flavors = flavors
|
||||
self.cluster.create(mock.Mock(),
|
||||
self.cluster_name,
|
||||
self.datastore,
|
||||
@ -214,15 +218,19 @@ class MongoDBClusterTest(trove_testtools.TestCase):
|
||||
@mock.patch.object(models.DBCluster, 'create')
|
||||
@mock.patch.object(QUOTAS, 'check_quotas')
|
||||
@mock.patch.object(remote, 'create_nova_client')
|
||||
@mock.patch.object(remote, 'create_neutron_client')
|
||||
@mock.patch.object(api, 'CONF')
|
||||
def test_create_with_lower_configsvr(self, mock_conf, mock_client,
|
||||
mock_check_quotas, mock_db_create,
|
||||
mock_ins_create, mock_task_api):
|
||||
def test_create_with_lower_configsvr(self, mock_conf, mock_neutron_client,
|
||||
mock_nova_client, ock_check_quotas,
|
||||
mock_db_create, mock_ins_create,
|
||||
mock_task_api):
|
||||
mock_conf.get = mock.Mock(
|
||||
return_value=FakeOptGroup(num_config_servers_per_cluster=1))
|
||||
instances = self.instances
|
||||
flavors = mock.Mock()
|
||||
mock_client.return_value.flavors = flavors
|
||||
networks = mock.Mock()
|
||||
mock_nova_client.return_value.flavors = flavors
|
||||
mock_neutron_client.return_value.find_resource = networks
|
||||
self.cluster.create(mock.Mock(),
|
||||
self.cluster_name,
|
||||
self.datastore,
|
||||
@ -237,15 +245,19 @@ class MongoDBClusterTest(trove_testtools.TestCase):
|
||||
@mock.patch.object(models.DBCluster, 'create')
|
||||
@mock.patch.object(QUOTAS, 'check_quotas')
|
||||
@mock.patch.object(remote, 'create_nova_client')
|
||||
@mock.patch.object(remote, 'create_neutron_client')
|
||||
@mock.patch.object(api, 'CONF')
|
||||
def test_create_with_higher_configsvr(self, mock_conf, mock_client,
|
||||
mock_check_quotas, mock_db_create,
|
||||
mock_ins_create, mock_task_api):
|
||||
def test_create_with_higher_configsvr(self, mock_conf, mock_neutron_client,
|
||||
mock_nova_client, mock_check_quotas,
|
||||
mock_db_create, mock_ins_create,
|
||||
mock_task_api):
|
||||
mock_conf.get = mock.Mock(
|
||||
return_value=FakeOptGroup(num_config_servers_per_cluster=5))
|
||||
instances = self.instances
|
||||
flavors = mock.Mock()
|
||||
mock_client.return_value.flavors = flavors
|
||||
networks = mock.Mock()
|
||||
mock_nova_client.return_value.flavors = flavors
|
||||
mock_neutron_client.return_value.find_resource = networks
|
||||
self.cluster.create(mock.Mock(),
|
||||
self.cluster_name,
|
||||
self.datastore,
|
||||
@ -260,15 +272,19 @@ class MongoDBClusterTest(trove_testtools.TestCase):
|
||||
@mock.patch.object(models.DBCluster, 'create')
|
||||
@mock.patch.object(QUOTAS, 'check_quotas')
|
||||
@mock.patch.object(remote, 'create_nova_client')
|
||||
@mock.patch.object(remote, 'create_neutron_client')
|
||||
@mock.patch.object(api, 'CONF')
|
||||
def test_create_with_higher_mongos(self, mock_conf, mock_client,
|
||||
mock_check_quotas, mock_db_create,
|
||||
mock_ins_create, mock_task_api):
|
||||
def test_create_with_higher_mongos(self, mock_conf, mock_neutron_client,
|
||||
mock_nova_client, mock_check_quotas,
|
||||
mock_db_create, mock_ins_create,
|
||||
mock_task_api):
|
||||
mock_conf.get = mock.Mock(
|
||||
return_value=FakeOptGroup(num_query_routers_per_cluster=4))
|
||||
instances = self.instances
|
||||
flavors = mock.Mock()
|
||||
mock_client.return_value.flavors = flavors
|
||||
networks = mock.Mock()
|
||||
mock_nova_client.return_value.flavors = flavors
|
||||
mock_neutron_client.return_value.find_resource = networks
|
||||
self.cluster.create(mock.Mock(),
|
||||
self.cluster_name,
|
||||
self.datastore,
|
||||
|
Loading…
x
Reference in New Issue
Block a user