def test_get(self): name = "scheduler" c = utils.create_component_status(name=name) if utils.is_reachable(c.config.api_host): from_get = c.get() self.assertIsInstance(from_get, K8sComponentStatus) self.assertEqual(c, from_get)
def test_init_with_name(self): name = "yo-name" c = utils.create_component_status(name=name) self.assertIsNotNone(c) self.assertIsInstance(c, K8sComponentStatus) self.assertEqual('ComponentStatus', c.obj_type) self.assertEqual(c.name, name) self.assertIsInstance(c.config, K8sConfig)
def test_struct_k8s_component_status(self): name = "yo-name" c = utils.create_component_status(name=name) self.assertIsInstance(c, K8sComponentStatus) self.assertIsInstance(c.base_url, str) self.assertIsInstance(c.config, K8sConfig) self.assertIsInstance(c.model, ComponentStatus) self.assertIsInstance(c.name, str) self.assertIsInstance(c.obj_type, str)
def test_init_with_name_and_config(self): nspace = "default" config = K8sConfig(kubeconfig=utils.kubeconfig_fallback, namespace=nspace) name = "yo-name" c = utils.create_component_status(config=config, name=name) self.assertIsNotNone(c) self.assertIsInstance(c, K8sComponentStatus) self.assertEqual(c.name, name) self.assertEqual('ComponentStatus', c.obj_type) self.assertIsInstance(c.config, K8sConfig)
def test_list(self): name = "yo-{0}".format(str(uuid.uuid4().get_hex()[:16])) components = utils.create_component_status(name=name) if utils.is_reachable(components.config.api_host): _list = components.list() etcd_pattern = re.compile("etcd-") _filtered = filter( lambda x: etcd_pattern.match(x['metadata']['name']) is not None, _list) self.assertIsInstance(_filtered, list) self.assertGreaterEqual(len(_filtered), 1)
def test_list(self): name = "yo-{0}".format(str(uuid.uuid4().hex[:16])) components = utils.create_component_status(name=name) if utils.is_reachable(components.config.api_host): _list = components.list() for x in _list: self.assertIsInstance(x, K8sComponentStatus) etcd_pattern = re.compile("etcd-") _filtered = list( filter(lambda x: etcd_pattern.match(x.name) is not None, _list)) self.assertIsInstance(_filtered, list) self.assertGreaterEqual(len(_filtered), 1)
def test_get_nonexistent(self): name = "yo-component" c = utils.create_component_status(name=name) if utils.is_reachable(c.config.api_host): with self.assertRaises(NotFoundException): c.get()
def test_init_with_invalid_name(self): name = object() with self.assertRaises(SyntaxError): utils.create_component_status(name=name)