Merge "Add FloatingIPPool class for neutron client"
This commit is contained in:
commit
1781909744
|
@ -13,10 +13,14 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import mock
|
||||
import neutronclient
|
||||
from neutronclient.common import exceptions as neutron_exceptions
|
||||
from oslo_config import cfg
|
||||
from oslo_config import fixture
|
||||
|
||||
from blazar import tests
|
||||
from blazar.utils.openstack import exceptions
|
||||
from blazar.utils.openstack import neutron
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
@ -34,3 +38,22 @@ class TestBlazarNeutronClient(tests.TestCase):
|
|||
client = neutron.BlazarNeutronClient(**kwargs)
|
||||
self.assertEqual("http://foo:8080/identity/v3",
|
||||
client.neutron.httpclient.session.auth.auth_url)
|
||||
|
||||
|
||||
class TestFloatingIPPool(tests.TestCase):
|
||||
def setUp(self):
|
||||
super(TestFloatingIPPool, self).setUp()
|
||||
|
||||
@mock.patch.object(neutronclient.v2_0.client.Client, 'show_network')
|
||||
def test_init_floatingippool(self, mock_net):
|
||||
mock_net.return_value = {'network': {'id': 'net-id'}}
|
||||
client = neutron.FloatingIPPool('net-id')
|
||||
self.assertEqual('net-id', client.network_id)
|
||||
mock_net.assert_called_once_with('net-id')
|
||||
|
||||
@mock.patch.object(neutronclient.v2_0.client.Client, 'show_network')
|
||||
def test_init_with_invalid_network_id(self, mock_net):
|
||||
mock_net.side_effect = neutron_exceptions.NotFound()
|
||||
|
||||
self.assertRaises(exceptions.FloatingIPNetworkNotFound,
|
||||
neutron.FloatingIPPool, 'invalid-net-id')
|
||||
|
|
|
@ -47,3 +47,7 @@ class ResourceProviderNotFound(exceptions.BlazarException):
|
|||
class InventoryUpdateFailed(exceptions.BlazarException):
|
||||
msg_fmt = _("Failed to update the inventory of resource provider "
|
||||
"%(resource_provider)s")
|
||||
|
||||
|
||||
class FloatingIPNetworkNotFound(exceptions.InvalidInput):
|
||||
msg_fmt = _("Failed to find network %(network)s")
|
||||
|
|
|
@ -15,11 +15,14 @@
|
|||
|
||||
from keystoneauth1.identity import v3
|
||||
from keystoneauth1 import session
|
||||
from neutronclient.common import exceptions as neutron_exceptions
|
||||
from neutronclient.v2_0 import client as neutron_client
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
|
||||
from blazar.utils.openstack import exceptions
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
@ -55,3 +58,17 @@ class BlazarNeutronClient(object):
|
|||
project_domain_name=project_domain_name)
|
||||
sess = session.Session(auth=auth)
|
||||
self.neutron = neutron_client.Client(session=sess)
|
||||
|
||||
|
||||
class FloatingIPPool(BlazarNeutronClient):
|
||||
|
||||
def __init__(self, network_id, **kwargs):
|
||||
super(FloatingIPPool, self).__init__(**kwargs)
|
||||
|
||||
try:
|
||||
self.neutron.show_network(network_id)
|
||||
except neutron_exceptions.NotFound:
|
||||
LOG.info('Failed to find network %s.', network_id)
|
||||
raise exceptions.FloatingIPNetworkNotFound(network=network_id)
|
||||
|
||||
self.network_id = network_id
|
||||
|
|
Loading…
Reference in New Issue