예제 #1
0
    def test_migration_rollback(self):
        responses.reset()
        responses.add(method=responses.GET, match_querystring=True,
                      url=re.compile(r"(.*)/status-summary\?component_type=MP_TO_POLICY_MIGRATION"),
                      status=200, json={"overall_migration_status": "FAIL"})
        self._register_api_responses()

        _, _, _, _, os_port_parent, _ = self.port_fixture()
        migr_provider = mp_to_policy_migration.Provider()
        mngr_provider = provider_nsx_mgmt.Provider()

        mngr_meta = mngr_provider.port_realize(os_port_parent)
        inv = self.inventory.inv[Inventory.PORTS]
        mngr_port: dict = self.get_by_name(inv, os_port_parent.get("id"))

        try:
            with patch.object(mp_to_policy_migration.Provider, '_try_rollback') as _try_rollback_mock:
                migr_provider.migrate_ports([mngr_port.get("id")])
        except RuntimeError as e:
            self.assertEqual(True, "Migration status check FAILED" in str(e))
            _try_rollback_mock.assert_called_once_with(migr_data={
                'migration_data': [{
                    'type': 'LOGICAL_PORT',
                    'resource_ids': [
                        {
                            'manager_id': mngr_meta.id,
                            'policy_id': mngr_meta.id
                        }
                    ]}]})
            return
        assert False
예제 #2
0
 def test_migration_service_not_enabled(self):
     responses.reset()
     responses.add(url=re.compile(r".*"), status=500)
     try:
         mp_to_policy_migration.Provider()
     except RuntimeError as e:
         self.assertEqual(True, "MP-TO-POLICY API not enabled" in str(e))
         return
     assert False
예제 #3
0
    def test_bulk_migration(self):
        _, _, _, os_qos, os_port_parent, _ = self.port_fixture()

        migr_provider = mp_to_policy_migration.Provider()
        mngr_provider = provider_nsx_mgmt.Provider()
        plcy_provider = provider_nsx_policy.Provider()

        mngr_provider.qos_realize(os_qos)
        mngr_net_meta = mngr_provider.network_realize(3200)
        os_port_parent["vif_details"]["nsx-logical-switch-id"] = mngr_net_meta.id
        mngr_port_meta = mngr_provider.port_realize(os_port_parent)

        mngr_port_inv = self.inventory.inv[Inventory.PROFILES]
        mngr_qos: dict = self.get_by_name(mngr_port_inv, os_qos.get("id"))

        pb = mp_to_policy_migration.PayloadBuilder()
        payload = pb\
            .sw_profiles([(mngr_qos.get("id"), "QosSwitchingProfile")])\
            .switch(mngr_net_meta.id)\
            .ports([mngr_port_meta.id])\
            .build()
        migr_provider.migrate_bulk(payload)

        plcy_provider.metadata_refresh(plcy_provider.SEGMENT)
        plcy_net_meta = plcy_provider.network_realize(3200)
        mngr_net_inv = self.inventory.inv[Inventory.SWITCHES]
        plcy_net_inv = self.inventory.inv[Inventory.SEGMENTS]
        mngr_port_inv = self.inventory.inv[Inventory.PORTS]
        mngr_net: dict = mngr_net_inv.get(mngr_net_meta.id)
        plcy_net: dict = plcy_net_inv.get(plcy_net_meta.id)
        prfls = plcy_provider.get_non_default_switching_profiles()
        mngr_port: dict = self.get_by_name(mngr_port_inv, os_port_parent.get("id"))
        plcy_port = plcy_provider.get_port(os_port_parent.get("id"))[1]

        policy_qos_profile = prfls[0]
        self.assertEqual(os_qos.get("id"), policy_qos_profile.get("display_name"))
        self.assertEqual("QoSProfile", policy_qos_profile.get("resource_type"))
        self.assertEqual(mngr_qos.get("id"), policy_qos_profile.get("id"))
        self.assertEqual("nsx_policy", mngr_qos.get("_create_user"))
        self.assertEqual(mngr_qos.get("tags"), policy_qos_profile.get("tags"))

        self.assertEqual(os_port_parent.get("id"), plcy_port.get("display_name"))
        self.assertEqual("SegmentPort", plcy_port.get("resource_type"))
        self.assertEqual(mngr_port.get("id"), plcy_port.get("id"))
        self.assertEqual("nsx_policy", mngr_port.get("_create_user"))
        self.assertEqual(mngr_port.get("tags"), plcy_port.get("tags"))

        self.assertEqual(mngr_net_meta.id, plcy_net_meta.id)
        self.assertEqual(mngr_net.get("id"), plcy_net.get("id"))
        self.assertEqual(mngr_net.get("display_name"), plcy_net.get("display_name"))
        self.assertEqual(True, str(mngr_net.get("vlan")) in plcy_net.get("vlan_ids"))
        self.assertEqual("Segment", plcy_net.get("resource_type"))
        self.assertEqual("LogicalSwitch", mngr_net.get("resource_type"))
        self.assertEqual("nsx_policy", mngr_net.get("_create_user"))
예제 #4
0
    def test_port_migration(self):
        _, _, _, _, os_port_parent, _ = self.port_fixture()
        migr_provider = mp_to_policy_migration.Provider()
        mngr_provider = provider_nsx_mgmt.Provider()
        plcy_provider = provider_nsx_policy.Provider()

        mngr_provider.port_realize(os_port_parent)
        inv = self.inventory.inv[Inventory.PORTS]
        mngr_port: dict = self.get_by_name(inv, os_port_parent.get("id"))

        migr_provider.migrate_ports([mngr_port.get("id")])
        plcy_port = plcy_provider.get_port(os_port_parent.get("id"))[1]

        self.assertEqual(os_port_parent.get("id"), plcy_port.get("display_name"))
        self.assertEqual("SegmentPort", plcy_port.get("resource_type"))
        self.assertEqual(mngr_port.get("id"), plcy_port.get("id"))
        self.assertEqual("nsx_policy", mngr_port.get("_create_user"))
        self.assertEqual(mngr_port.get("tags"), plcy_port.get("tags"))
예제 #5
0
    def __init__(self,
                 rpc: NSXv3ServerRpcApi,
                 callback: Callable[[list or str, Callable[[str], None]],
                                    None],
                 kpi: Callable[[], dict],
                 mngr_provider: m_prvdr.Provider,
                 plcy_provider: p_prvdr.Provider,
                 migr_provider: mi_prvdr.Provider = None):
        self.rpc = rpc
        self.callback = callback
        self.kpi = kpi

        self.mngr_provider = mngr_provider
        self.plcy_provider = plcy_provider

        LOG.info("Detected NSX-T %s version.",
                 self.mngr_provider.client.version)

        # Enable MP-to-Policy migration if force_mp_to_policy=True
        self.force_mp_to_policy = cfg.CONF.AGENT.force_mp_to_policy
        if self.mngr_provider.client.version < (3, 1):
            self.force_mp_to_policy = False
            LOG.warning(
                "MP-TO-POLICY API is supported from NSX-T ver. 3.1.x onward.")

        if self.force_mp_to_policy:
            try:
                self.force_mp_to_policy = False
                self.migr_provider = mi_prvdr.Provider()
                self.force_mp_to_policy = True
            except Exception as e:
                LOG.error(str(e))
                self.force_mp_to_policy = False
                LOG.critical("MP-to-Policy Migration Functionality disabled.")
            else:
                try:
                    self._promote_switching_profiles()
                except Exception as e:
                    LOG.warning(str(e))

        self.age = int(time.time())
        # Initializing metadata
        self.all(dryrun=True)
예제 #6
0
    def test_migrate_sw_profiles_supported_type(self):
        _, _, _, os_qos, _, _ = self.port_fixture()
        migr_provider = mp_to_policy_migration.Provider()
        mngr_provider = provider_nsx_mgmt.Provider()
        plcy_provider = provider_nsx_policy.Provider()

        mngr_provider.qos_realize(os_qos)
        inv = self.inventory.inv[Inventory.PROFILES]
        mngr_qos: dict = self.get_by_name(inv, os_qos.get("id"))

        migr_provider.migrate_sw_profiles(
            not_migrated=[(mngr_qos.get("id"), "QosSwitchingProfile")])
        prfls = plcy_provider.get_non_default_switching_profiles()

        policy_qos_profile = prfls[0]
        self.assertEqual(os_qos.get("id"), policy_qos_profile.get("display_name"))
        self.assertEqual("QoSProfile", policy_qos_profile.get("resource_type"))
        self.assertEqual(mngr_qos.get("id"), policy_qos_profile.get("id"))
        self.assertEqual("nsx_policy", mngr_qos.get("_create_user"))
        self.assertEqual(mngr_qos.get("tags"), policy_qos_profile.get("tags"))
예제 #7
0
    def test_port_already_migrated(self):
        _, _, _, _, os_port_parent, _ = self.port_fixture()
        migr_provider = mp_to_policy_migration.Provider()
        mngr_provider = provider_nsx_mgmt.Provider()
        plcy_provider = provider_nsx_policy.Provider()

        mngr_provider.port_realize(os_port_parent)
        inv = self.inventory.inv[Inventory.PORTS]
        mngr_port: dict = self.get_by_name(inv, os_port_parent.get("id"))

        migr_provider.migrate_ports([mngr_port.get("id")])
        plcy_port = plcy_provider.get_port(os_port_parent.get("id"))[1]

        self.assertEqual(os_port_parent.get("id"), plcy_port.get("display_name"))

        try:
            migr_provider.migrate_ports([mngr_port.get("id")])
        except RuntimeError as e:
            self.assertEqual(True, "Policy Resource already exists" in str(e))
            return
        assert False
예제 #8
0
    def test_switch_migration(self):
        migr_provider = mp_to_policy_migration.Provider()
        mngr_provider = provider_nsx_mgmt.Provider()
        plcy_provider = provider_nsx_policy.Provider()

        mngr_meta = mngr_provider.network_realize(10)
        migr_provider.migrate_switch(mngr_meta.id)
        plcy_provider.metadata_refresh(plcy_provider.SEGMENT)
        plcy_meta = plcy_provider.network_realize(10)

        mngr_inv = self.inventory.inv[Inventory.SWITCHES]
        plcy_inv = self.inventory.inv[Inventory.SEGMENTS]
        mngr_net: dict = mngr_inv.get(mngr_meta.id)
        plcy_net: dict = plcy_inv.get(plcy_meta.id)

        self.assertEqual(mngr_meta.id, plcy_meta.id)
        self.assertEqual(mngr_net.get("id"), plcy_net.get("id"))
        self.assertEqual(mngr_net.get("display_name"), plcy_net.get("display_name"))
        self.assertEqual(True, str(mngr_net.get("vlan")) in plcy_net.get("vlan_ids"))
        self.assertEqual("Segment", plcy_net.get("resource_type"))
        self.assertEqual("LogicalSwitch", mngr_net.get("resource_type"))
        self.assertEqual("nsx_policy", mngr_net.get("_create_user"))
예제 #9
0
    def test_migrate_sw_profiles_not_supported_type(self):
        migr_provider = mp_to_policy_migration.Provider()

        m_data = migr_provider.migrate_sw_profiles(
            not_migrated=[("not-supported-id", "PortMirroringSwitchingProfile")])
        self.assertEqual(None, m_data)