diff --git a/baremetal_network_provisioning/ml2/hpironicextensiondriver.py b/baremetal_network_provisioning/ml2/hpironicextensiondriver.py deleted file mode 100644 index 1121dca..0000000 --- a/baremetal_network_provisioning/ml2/hpironicextensiondriver.py +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright (c) 2015 OpenStack Foundation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from neutron.api import extensions as neutron_extensions -from neutron.plugins.ml2 import driver_api as api - -from baremetal_network_provisioning.ml2 import extensions - -from oslo_log import log as logging - -LOG = logging.getLogger(__name__) - - -class HPIronicExtensionDriver(api.ExtensionDriver): - _supported_extension_aliases = 'bnp-switch' - - def initialize(self): - neutron_extensions.append_api_extensions_path(extensions.__path__) - LOG.info(_("HPIronicExtensionDriver initialization complete")) - - @property - def extension_alias(self): - """Supported extension alias. - - identifying the core API extension supported - by this BNP driver - """ - return self._supported_extension_aliases diff --git a/baremetal_network_provisioning/ml2/mechanism_hp.py b/baremetal_network_provisioning/ml2/mechanism_hp.py deleted file mode 100644 index 404a9f0..0000000 --- a/baremetal_network_provisioning/ml2/mechanism_hp.py +++ /dev/null @@ -1,203 +0,0 @@ -# Copyright (c) 2015 OpenStack Foundation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from oslo_config import cfg -from oslo_log import log as logging -from oslo_utils import importutils - -from neutron.common import constants as n_const -from neutron.extensions import portbindings -from neutron.plugins.common import constants -from neutron.plugins.ml2 import driver_api as api - -from baremetal_network_provisioning.common import constants as hp_const - - -LOG = logging.getLogger(__name__) -hp_opts = [ - cfg.StrOpt('net_provisioning_driver', - default='baremetal_network_provisioning.ml2' - '.hp_network_provisioning_driver.HPNetworkProvisioningDriver', - help=_("Driver to provision networks on the switches in" - "the cloud fabric")), -] -cfg.CONF.register_opts(hp_opts, "ml2_hp") - - -class HPMechanismDriver(api.MechanismDriver): - """Ml2 Mechanism front-end driver interface for bare - - metal provisioning. - """ - - def initialize(self): - self.conf = cfg.CONF - self._load_drivers() - self.vif_type = hp_const.HP_VIF_TYPE - self.vif_details = {portbindings.CAP_PORT_FILTER: True} - - def _load_drivers(self): - """Loads back end network provision driver from configuration.""" - driver_obj = self.conf.ml2_hp.net_provisioning_driver - if not driver_obj: - raise SystemExit(_('A network provisioning driver' - 'must be specified')) - self.np_driver = importutils.import_object(driver_obj) - - def create_port_precommit(self, context): - """create_port_precommit.""" - if not self._is_port_of_interest(context): - return - port_dict = self._construct_port(context) - try: - self.np_driver.create_port(port_dict) - except Exception as e: - raise e - - def create_port_postcommit(self, context): - """create_port_postcommit.""" - pass - - def update_port_precommit(self, context): - """update_port_precommit.""" - vnic_type = self._get_vnic_type(context) - profile = self._get_binding_profile(context) - if vnic_type != portbindings.VNIC_BAREMETAL or not profile: - return - port_dict = self._construct_port(context) - host_id = context.current['binding:host_id'] - bind_port_dict = port_dict.get('port') - bind_port_dict['host_id'] = host_id - self.np_driver.update_port(port_dict) - - def update_port_postcommit(self, context): - """update_port_postcommit.""" - pass - - def delete_port_precommit(self, context): - """delete_port_postcommit.""" - vnic_type = self._get_vnic_type(context) - port_id = context.current['id'] - if vnic_type == portbindings.VNIC_BAREMETAL: - self.np_driver.delete_port(port_id) - - def delete_port_postcommit(self, context): - pass - - def bind_port(self, context): - """bind_port for claiming the ironic port.""" - LOG.debug("HPMechanismDriver Attempting to bind port %(port)s on " - "network %(network)s", - {'port': context.current['id'], - 'network': context.network.current['id']}) - port_id = context.current['id'] - for segment in context.segments_to_bind: - segmentation_id = segment.get(api.SEGMENTATION_ID) - if self._is_vlan_segment(segment, context): - port_status = n_const.PORT_STATUS_ACTIVE - if not self._is_port_of_interest(context): - return - host_id = context.current['binding:host_id'] - if host_id: - port = self._construct_port(context, segmentation_id) - b_status = self.np_driver.bind_port_to_segment(port) - if b_status == hp_const.BIND_SUCCESS: - context.set_binding(segment[api.ID], - self.vif_type, - self.vif_details, - status=port_status) - LOG.debug("port bound using segment for port %(port)s", - {'port': port_id}) - return - else: - LOG.debug("port binding pass for %(segment)s", - {'segment': segment}) - return - else: - LOG.debug("Ignoring %(seg)s for port %(port)s", - {'seg': segmentation_id, - 'port': port_id}) - return - - def _is_vlan_segment(self, segment, context): - """Verify a segment is valid for the HP MechanismDriver. - - Verify the requested segment is supported by HP and return True or - False to indicate this to callers. - """ - network_type = segment[api.NETWORK_TYPE] - if network_type in [constants.TYPE_VLAN]: - return True - else: - False - - def _construct_port(self, context, segmentation_id=None): - """"Contruct port dict.""" - port = context.current - port_id = port['id'] - network_id = port['network_id'] - is_lag = False - bind_port_dict = None - profile = self._get_binding_profile(context) - local_link_information = profile.get('local_link_information') - host_id = context.current['binding:host_id'] - LOG.debug("_construct_port local link info %(local_info)s", - {'local_info': local_link_information}) - if local_link_information and len(local_link_information) > 1: - is_lag = True - port_dict = {'port': - {'id': port_id, - 'network_id': network_id, - 'is_lag': is_lag, - 'switchports': local_link_information, - 'host_id': host_id - } - } - if segmentation_id: - bind_port_dict = port_dict.get('port') - bind_port_dict['segmentation_id'] = segmentation_id - bind_port_dict['access_type'] = hp_const.ACCESS - else: - return port_dict - final_dict = {'port': bind_port_dict} - LOG.debug("final port dict %(final_dict)s", - {'final_dict': final_dict}) - return final_dict - - def _get_binding_profile(self, context): - """get binding profile from port context.""" - profile = context.current.get(portbindings.PROFILE, {}) - if not profile: - LOG.debug("Missing profile in port binding") - return profile - - def _get_vnic_type(self, context): - """get vnic type for baremetal.""" - vnic_type = context.current.get(portbindings.VNIC_TYPE, "") - if not vnic_type: - return None - else: - return vnic_type - - def _is_port_of_interest(self, context): - vnic_type = self._get_vnic_type(context) - binding_profile = self._get_binding_profile(context) - if vnic_type != portbindings.VNIC_BAREMETAL or not binding_profile: - return False - local_link_information = binding_profile.get('local_link_information') - if not local_link_information: - LOG.debug("local_link_information list does not exist in profile") - return False - return True diff --git a/baremetal_network_provisioning/tests/unit/ml2/test_mechanism_hp.py b/baremetal_network_provisioning/tests/unit/ml2/test_mechanism_hp.py deleted file mode 100644 index c192695..0000000 --- a/baremetal_network_provisioning/tests/unit/ml2/test_mechanism_hp.py +++ /dev/null @@ -1,226 +0,0 @@ -# Copyright 2015 OpenStack Foundation -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -from baremetal_network_provisioning.common import constants as hp_const -from baremetal_network_provisioning.ml2 import (hp_network_provisioning_driver - as np_drv) -from baremetal_network_provisioning.ml2 import mechanism_hp as hp_mech - -import contextlib - -import mock -from oslo_config import cfg - -from neutron.extensions import portbindings -from neutron.tests import base -CONF = cfg.CONF - - -class TestHPMechDriver(base.BaseTestCase): - """Test class for mech driver.""" - - def setUp(self): - super(TestHPMechDriver, self).setUp() - self.driver = hp_mech.HPMechanismDriver() - self.np_driver = np_drv.HPNetworkProvisioningDriver() - self.driver.initialize() - self.driver._load_drivers() - - def _get_port_context(self, tenant_id, net_id, vm_id, network): - """Get port context.""" - port = {'device_id': vm_id, - 'device_owner': 'compute', - 'binding:host_id': 'ironic', - 'name': 'test-port', - 'tenant_id': tenant_id, - 'id': 123456, - 'network_id': net_id, - 'binding:profile': - {'local_link_information': [{'switch_id': '11:22:33:44:55:66', - 'port_id': 'Tengig0/1'}]}, - 'binding:vnic_type': 'baremetal', - 'admin_state_up': True, - } - return FakePortContext(port, port, network) - - def _get_network_context(self, tenant_id, net_id, seg_id, shared): - """Get network context.""" - network = {'id': net_id, - 'tenant_id': tenant_id, - 'name': 'test-net', - 'shared': shared} - network_segments = [{'segmentation_id': seg_id}] - return FakeNetworkContext(network, network_segments, network) - - def _get_port_dict(self): - """Get port dict.""" - port_dict = {'port': - {'segmentation_id': 1001, - 'host_id': 'ironic', - 'access_type': hp_const.ACCESS, - 'switchports': - [{'port_id': 'Tengig0/1', - 'switch_id': '11:22:33:44:55:66'}], - 'id': 123456, - 'network_id': "net1-id", - 'is_lag': False}} - return port_dict - - def test_create_port_precommit(self): - """Test create_port_precommit method.""" - fake_port_dict = mock.Mock() - fake_context = mock.Mock() - with contextlib.nested( - mock.patch.object(hp_mech.HPMechanismDriver, - '_is_port_of_interest', - return_value=True), - mock.patch.object(hp_mech.HPMechanismDriver, - '_construct_port', - return_value=fake_port_dict), - mock.patch.object(np_drv.HPNetworkProvisioningDriver, - 'create_port', - return_value=None) - ) as (is_port, cons_port, c_port): - self.driver.create_port_precommit(fake_context) - is_port.assert_called_with(fake_context) - cons_port.assert_called_with(fake_context) - c_port.assert_called_with(fake_port_dict) - - def test_delete_port_precommit(self): - """Test delete_port_precommit method.""" - tenant_id = 'ten-1' - network_id = 'net1-id' - segmentation_id = 1001 - vm_id = 'vm1' - network_context = self._get_network_context(tenant_id, - network_id, - segmentation_id, - False) - - port_context = self._get_port_context(tenant_id, - network_id, - vm_id, - network_context) - port_id = port_context.current['id'] - with contextlib.nested( - mock.patch.object(hp_mech.HPMechanismDriver, - '_get_vnic_type', - return_value=portbindings.VNIC_BAREMETAL), - mock.patch.object(np_drv.HPNetworkProvisioningDriver, - 'delete_port', - return_value=None) - ) as (vnic_type, d_port): - self.driver.delete_port_precommit(port_context) - vnic_type.assert_called_with(port_context) - d_port.assert_called_with(port_id) - - def test__construct_port(self): - """Test _construct_port method.""" - tenant_id = 'ten-1' - network_id = 'net1-id' - segmentation_id = 1001 - vm_id = 'vm1' - fake_port_dict = self._get_port_dict() - network_context = self._get_network_context(tenant_id, - network_id, - segmentation_id, - False) - - port_context = self._get_port_context(tenant_id, - network_id, - vm_id, - network_context) - port_dict = self.driver._construct_port(port_context, segmentation_id) - self.assertEqual(port_dict, fake_port_dict) - - def test__get_binding_profile(self): - """Test _get_binding_profile method.""" - tenant_id = 'ten-1' - network_id = 'net1-id' - segmentation_id = 1001 - vm_id = 'vm1' - network_context = self._get_network_context(tenant_id, - network_id, - segmentation_id, - False) - - port_context = self._get_port_context(tenant_id, - network_id, - vm_id, - network_context) - fake_profile = {'local_link_information': - [{'switch_id': '11:22:33:44:55:66', - 'port_id': 'Tengig0/1'}]} - profile = self.driver._get_binding_profile(port_context) - self.assertEqual(profile, fake_profile) - - def test__get_vnic_type(self): - """Test _get_binding_profile method.""" - tenant_id = 'ten-1' - network_id = 'net1-id' - segmentation_id = 1001 - vm_id = 'vm1' - network_context = self._get_network_context(tenant_id, - network_id, - segmentation_id, - False) - - port_context = self._get_port_context(tenant_id, - network_id, - vm_id, - network_context) - vnic_type = self.driver._get_vnic_type(port_context) - self.assertEqual(vnic_type, 'baremetal') - - -class FakeNetworkContext(object): - """To generate network context for testing purposes only.""" - - def __init__(self, network, segments=None, original_network=None): - self._network = network - self._original_network = original_network - self._segments = segments - - @property - def current(self): - return self._network - - @property - def original(self): - return self._original_network - - @property - def network_segments(self): - return self._segments - - -class FakePortContext(object): - """To generate port context for testing purposes only.""" - - def __init__(self, port, original_port, network): - self._port = port - self._original_port = original_port - self._network_context = network - - @property - def current(self): - return self._port - - @property - def original(self): - return self._original_port - - @property - def network(self): - return self._network_context diff --git a/etc/ml2_conf_hp.ini b/etc/ml2_conf_hp.ini deleted file mode 100644 index 09f0645..0000000 --- a/etc/ml2_conf_hp.ini +++ /dev/null @@ -1,14 +0,0 @@ -[ml2_hp] -# (StrOpt) Back end driver -# -# net_provisioning_driver = -# Example : net_provisioning_driver = baremetal_network_provisioning.drivers.hp.hp_snmp_provisioning_driver.HPSNMPProvisioningDriver - -[default] -# snmp_timeout = -# Example snmp_timeout = 3 -#(IntOpt)Timeout in seconds to wait for SNMP request completion - -# snmp_retries -# Example snmp_retries = 5 -# (IntOpt) Number of retries to be done for the SNMP request after the timeout