def test_get_by_labels_without_name(self): name = "yocontainer" container = _utils.create_container(name=name) name = "yopod-{0}".format(str(uuid.uuid4())) pod = _utils.create_pod(name=name) pod.add_container(container) pod.add_label("test.label", "hello") if _utils.is_reachable(pod.config): pod.create() pods = K8sPod.get_by_labels(config=pod.config, labels={'test.label': "hello"}) self.assertIsInstance(pods, list) self.assertEqual(1, len(pods)) self.assertEqual(pod, pods[0]) pods = K8sPod.get_by_labels(config=pod.config, labels={'test.label': "world"}) self.assertEqual(0, len(pods))
def test_get_by_labels_nonexistent(self): name = "yopod-{0}".format(str(uuid.uuid4())) config = K8sConfig(kubeconfig=_utils.kubeconfig_fallback) if _utils.is_reachable(config): pods = K8sPod.get_by_labels(config=config, labels={'name': name}) self.assertIsInstance(pods, list) self.assertEqual(0, len(pods))
def test_update_labels(self): name = "yocontainer" container = _utils.create_container(name=name) name = "yopod-{0}".format(str(uuid.uuid4())) pod = _utils.create_pod(name=name) pod.add_container(container) if _utils.is_reachable(pod.config): pod.create() labels = pod.labels labels['yomama'] = 'sofat' pods = K8sPod.get_by_labels(config=pod.config, labels=labels) self.assertIsInstance(pods, list) self.assertEqual(0, len(pods)) pod.labels = labels pod.update() pods = K8sPod.get_by_labels(config=pod.config, labels=labels) self.assertIsInstance(pods, list) self.assertEqual(1, len(pods))
def _check_pod_readiness(self): if self.current_replicas == self.desired_replicas: pods = K8sPod.get_by_labels(config=self.config, labels=self.pod_labels) for pod in pods: try: if not pod.is_ready(): raise PodNotReadyException(pod.name) except NotFoundException: pass except PodNotReadyException: return False return True return False
def test_get_by_labels(self): name = "yocontainer" container = _utils.create_container(name=name) name = "yopod-{0}".format(str(uuid.uuid4())) pod = _utils.create_pod(name=name) pod.add_container(container) if _utils.is_reachable(pod.config): pod.create() pods = K8sPod.get_by_labels(config=pod.config, labels={'name': name}) self.assertIsInstance(pods, list) self.assertEqual(1, len(pods)) self.assertEqual(pod, pods[0])
def get_pods(self): pods = K8sPod.get_by_labels(config=self.config, labels=self.pod_labels) return pods
def test_get_by_labels_invalid_args(self): name = object() config = _utils.create_config() with self.assertRaises(SyntaxError): K8sPod.get_by_labels(config=config, labels=name)
def _get_pods(self, name=None, labels=None): if labels is None: return K8sPod.get_by_name(config=self.config, name=name) else: return K8sPod.get_by_labels(config=self.config, labels=labels)
def test_get_by_labels_none_args(self): config = _utils.create_config() with self.assertRaises(SyntaxError): K8sPod.get_by_labels(config=config)