def test_pre_hook_pending_upgrade_service(self, mocker: MockFixture) -> None: layer = Layer.load_from_yaml( os.path.join( os.getcwd(), "tests", "fixtures", "dummy_data", "aws_service_getting_started.yaml", ), None, ) idx = len(layer.modules) module_name: str = "hello" module: Optional[Module] = layer.get_module(module_name, idx) mocked_helm_list = mocker.patch( "modules.base.Helm.get_helm_list", return_value=[{ "name": f"{layer.name}-{module_name}" }], ) mocked_check_byok_ready = mocker.patch( "modules.base.K8sServiceModuleProcessor._check_byok_ready") with pytest.raises(UserErrors): K8sServiceModuleProcessor(module, layer).pre_hook(idx) mocked_helm_list.assert_called_once_with( kube_context=mocker.ANY, release=f"{layer.name}-{module_name}", status="pending-upgrade", ) mocked_check_byok_ready.assert_not_called()
def processor(self) -> K8sServiceModuleProcessor: # These tests don't depend on the layer and module, so we don't need to provide them # May need to fix this if future changes cause these tests to break processor = K8sServiceModuleProcessor(None, None) # type: ignore processor.FLAG_MULTIPLE_PORTS_SUPPORTED = True return processor
def test_is_linkerd_installed_not_installed( self, mocker: MockFixture, processor: K8sServiceModuleProcessor) -> None: mock_list_namespaces = mocker.patch( "modules.base.kubernetes.list_namespaces") mock_list_namespaces.return_value = [ make_linkerd_ns(), make_linkerd_ns(no_labels=True), make_linkerd_ns(linkerd_label="true", phase="Terminating"), ] assert processor._is_linkerd_installed() is False mock_list_namespaces.assert_called_once()
def test_validate_ports_flag_disabled_tcp( self, processor: K8sServiceModuleProcessor) -> None: processor.FLAG_MULTIPLE_PORTS_SUPPORTED = False ports = [ PortSpec("a", "tcp", 1, 80), ] self.validate_ports_assert( processor, ports, exception_type=UserErrors, exception_message="Cannot specify TCP ports in this cloud", )
def process_ports_assert( self, processor: K8sServiceModuleProcessor, data: Dict[Any, Any], *, expected: Optional[Dict[Any, Any]] = None, exception_type: Optional[Type[Exception]] = None, exception_message: Optional[str] = None, ) -> None: if expected is None: expected = copy.copy(data) if exception_type: with pytest.raises(exception_type) as e: processor._process_ports(data) if exception_message is not None: assert str(e.value) == exception_message else: processor._process_ports(data) assert data == expected
def read_ports(processor: K8sServiceModuleProcessor, raw: List[Dict[str, Any]]) -> List[PortSpec]: return processor._K8sServiceModuleProcessor__read_ports( raw) # type: ignore
def validate_ports(processor: K8sServiceModuleProcessor, ports: List[PortSpec]) -> None: processor._K8sServiceModuleProcessor__validate_ports( ports) # type: ignore
def transform_port(processor: K8sServiceModuleProcessor, data: Dict[Any, Any]) -> None: # mypy cannot see the mangled method, so we need to ignore type errors here processor._K8sServiceModuleProcessor__transform_port( data) # type: ignore
def is_linkerd_ns(ns: V1Namespace) -> bool: # Call mangled method since return K8sServiceModuleProcessor._K8sServiceModuleProcessor__is_linkerd_ns( ns) # type: ignore