def test_deploy_without_path_case1(self, *args): """Test if not path is found a dynamic path is used.""" # pylint: disable=too-many-locals (discover_new_path_mocked, should_deploy_mock, activate_mock, install_uni_flows_mock, install_nni_flows, chose_vlans_mock, log_mock) = args should_deploy_mock.return_value = False uni_a = get_uni_mocked(interface_port=2, tag_value=82, switch_id="switch_uni_a", is_valid=True) uni_z = get_uni_mocked(interface_port=3, tag_value=83, switch_id="switch_uni_z", is_valid=True) attributes = { "controller": get_controller_mock(), "name": "custom_name", "uni_a": uni_a, "uni_z": uni_z, "enabled": True, "dynamic_backup_path": True } dynamic_backup_path = Path([ get_link_mocked(endpoint_a_port=9, endpoint_b_port=10, metadata={"s_vlan": 5}), get_link_mocked(endpoint_a_port=11, endpoint_b_port=12, metadata={"s_vlan": 6}) ]) evc = EVC(**attributes) discover_new_path_mocked.return_value = dynamic_backup_path # storehouse initialization mock evc._storehouse.box = Mock() # pylint: disable=protected-access evc._storehouse.box.data = {} # pylint: disable=protected-access deployed = evc.deploy_to_path() self.assertEqual(should_deploy_mock.call_count, 1) self.assertEqual(discover_new_path_mocked.call_count, 1) self.assertEqual(activate_mock.call_count, 1) self.assertEqual(install_uni_flows_mock.call_count, 1) self.assertEqual(install_nni_flows.call_count, 1) self.assertEqual(chose_vlans_mock.call_count, 1) self.assertEqual(log_mock.info.call_count, 1) self.assertTrue(deployed)
def test_deploy_successfully(self, *args): """Test if all methods to deploy are called.""" # pylint: disable=too-many-locals (should_deploy_mock, activate_mock, install_uni_flows_mock, install_nni_flows, chose_vlans_mock, log_mock) = args should_deploy_mock.return_value = True uni_a = get_uni_mocked(interface_port=2, tag_value=82, switch_id="switch_uni_a", is_valid=True) uni_z = get_uni_mocked(interface_port=3, tag_value=83, switch_id="switch_uni_z", is_valid=True) primary_links = [ get_link_mocked(endpoint_a_port=9, endpoint_b_port=10, metadata={"s_vlan": 5}), get_link_mocked(endpoint_a_port=11, endpoint_b_port=12, metadata={"s_vlan": 6}) ] attributes = { "controller": get_controller_mock(), "name": "custom_name", "uni_a": uni_a, "uni_z": uni_z, "primary_links": primary_links } # Setup path to deploy path = Path() path.append(primary_links[0]) path.append(primary_links[1]) evc = EVC(**attributes) # storehouse mock evc._storehouse.box = Mock() # pylint: disable=protected-access evc._storehouse.box.data = {} # pylint: disable=protected-access deployed = evc.deploy_to_path(path) self.assertEqual(should_deploy_mock.call_count, 1) self.assertEqual(activate_mock.call_count, 1) self.assertEqual(install_uni_flows_mock.call_count, 1) self.assertEqual(install_nni_flows.call_count, 1) self.assertEqual(chose_vlans_mock.call_count, 1) log_mock.info.assert_called_once_with(f"{evc} was deployed.") self.assertTrue(deployed)
def test_deploy_fail(self, *args): """Test if all methods is ignored when the should_deploy is false.""" # pylint: disable=too-many-locals (sync_mock, should_deploy_mock, activate_mock, install_uni_flows_mock, install_nni_flows, chose_vlans_mock, discover_new_path, log_mock) = args uni_a = get_uni_mocked(interface_port=2, tag_value=82, switch_id="switch_uni_a", switch_dpid="switch_dpid_uni_a", is_valid=True) uni_z = get_uni_mocked(interface_port=3, tag_value=83, switch_id="switch_uni_z", switch_dpid="switch_dpid_uni_a", is_valid=True) attributes = { "controller": get_controller_mock(), "name": "custom_name", "uni_a": uni_a, "uni_z": uni_z, "primary_links": [ get_link_mocked(endpoint_a_port=9, endpoint_b_port=10, metadata={"s_vlan": 5}), get_link_mocked(endpoint_a_port=11, endpoint_b_port=12, metadata={"s_vlan": 6}) ] } evc = EVC(**attributes) deployed = evc.deploy_to_path() self.assertEqual(discover_new_path.call_count, 1) self.assertEqual(should_deploy_mock.call_count, 1) self.assertEqual(activate_mock.call_count, 0) self.assertEqual(install_uni_flows_mock.call_count, 0) self.assertEqual(install_nni_flows.call_count, 0) self.assertEqual(chose_vlans_mock.call_count, 0) self.assertEqual(log_mock.info.call_count, 0) self.assertEqual(sync_mock.call_count, 1) self.assertFalse(deployed)
def test_deploy_without_path_case1(self, *args): """Test if not path is found a dynamic path is used.""" # pylint: disable=too-many-locals ( discover_new_paths_mocked, should_deploy_mock, activate_mock, install_uni_flows_mock, install_nni_flows, chose_vlans_mock, log_mock, _, requests_mock, ) = args response = MagicMock() response.status_code = 201 requests_mock.return_value = response should_deploy_mock.return_value = False uni_a = get_uni_mocked( interface_port=2, tag_value=82, switch_id="switch_uni_a", is_valid=True, ) uni_z = get_uni_mocked( interface_port=3, tag_value=83, switch_id="switch_uni_z", is_valid=True, ) attributes = { "controller": get_controller_mock(), "name": "custom_name", "uni_a": uni_a, "uni_z": uni_z, "enabled": True, "dynamic_backup_path": False, } dynamic_backup_path = Path([ get_link_mocked( endpoint_a_port=9, endpoint_b_port=10, metadata={"s_vlan": 5}, ), get_link_mocked( endpoint_a_port=11, endpoint_b_port=12, metadata={"s_vlan": 6}, ), ]) evc = EVC(**attributes) discover_new_paths_mocked.return_value = [dynamic_backup_path] deployed = evc.deploy_to_path() self.assertEqual(should_deploy_mock.call_count, 1) self.assertEqual(discover_new_paths_mocked.call_count, 1) self.assertEqual(activate_mock.call_count, 1) self.assertEqual(install_uni_flows_mock.call_count, 1) self.assertEqual(install_nni_flows.call_count, 1) self.assertEqual(chose_vlans_mock.call_count, 1) log_mock.info.assert_called_with(f"{evc} was deployed.") self.assertTrue(deployed)
def test_deploy_error(self, *args): """Test if all methods is ignored when the should_deploy is false.""" # pylint: disable=too-many-locals ( sync_mock, remove_current_flows, should_deploy_mock, install_nni_flows, choose_vlans_mock, discover_new_paths, log_mock, ) = args install_nni_flows.side_effect = FlowModException should_deploy_mock.return_value = True uni_a = get_uni_mocked( interface_port=2, tag_value=82, switch_id="switch_uni_a", is_valid=True, ) uni_z = get_uni_mocked( interface_port=3, tag_value=83, switch_id="switch_uni_z", is_valid=True, ) primary_links = [ get_link_mocked(endpoint_a_port=9, endpoint_b_port=10, metadata={"s_vlan": 5}), get_link_mocked(endpoint_a_port=11, endpoint_b_port=12, metadata={"s_vlan": 6}), ] attributes = { "controller": get_controller_mock(), "name": "custom_name", "uni_a": uni_a, "uni_z": uni_z, "primary_links": primary_links, "queue_id": 5, } # Setup path to deploy path = Path() path.append(primary_links[0]) path.append(primary_links[1]) evc = EVC(**attributes) deployed = evc.deploy_to_path(path) self.assertEqual(discover_new_paths.call_count, 0) self.assertEqual(should_deploy_mock.call_count, 1) self.assertEqual(install_nni_flows.call_count, 1) self.assertEqual(choose_vlans_mock.call_count, 1) self.assertEqual(log_mock.error.call_count, 1) self.assertEqual(sync_mock.call_count, 0) self.assertEqual(remove_current_flows.call_count, 2) self.assertFalse(deployed)