def test_k8s_get_namespaces(): mock = MagicMock() with patch('intel.k8s.client_from_config', MagicMock(return_value=mock)): k8s.get_namespaces(None) called_methods = mock.method_calls assert len(called_methods) == 1 assert called_methods[0][0] == "list_namespace" assert len(called_methods[0][1]) == 0 assert len(called_methods[0][2]) == 0
def test_k8s_get_namespaces(): mock = MagicMock() with patch(CLIENT_CONFIG, MagicMock(return_value=mock)): k8s.get_namespaces(None) called_methods = mock.method_calls assert len(called_methods) == 1 assert called_methods[0][0] == "list_namespace" assert len(called_methods[0][1]) == 0 assert len(called_methods[0][2]) == 0
def cleanup(self): if self.active is False: return self.active = False # TODO: run cmk uninstallation here, when it's ready. # https://github.com/intelsdi-x/CPU-Manager-for-Kubernetes/pull/81 for node in self.nodes: k8s.unset_node_label(self.configuration, node, "namespace") self.nodes = [] k8s.delete_namespace(self.configuration, self.ns_name) timeout_destination = int(time.time()) + self.timeout while True: if int(time.time()) >= timeout_destination: raise Exception("Timeout after {} ".format(self.timeout) + "seconds on waiting removing namespace.") namespaces = k8s.get_namespaces(self.configuration)["items"] namespaces_list = list( map(lambda ns: ns["metadata"]["name"], namespaces)) if self.ns_name not in namespaces_list: break time.sleep(1)