def test_pod_add_volume_hostpath_no_path_specified(self): name = "yoname" obj = utils.create_pod(name=name) config = utils.create_config() vol = K8sVolume(config=config, name=name, mount_path="/var/test", type="hostPath") if utils.is_reachable(config.api_host): with self.assertRaises(UnprocessableEntityException): obj.add_volume(vol) obj.create()
def test_delete(self): name = "yoname" rs = utils.create_rs(name=name) config = utils.create_config() if utils.is_reachable(config.api_host): utils.cleanup_rs() result = rs.list() self.assertIsInstance(result, list) self.assertEqual(0, len(result))
def test_pod_add_volume_emptydir(self): name = "yoname" obj = utils.create_pod(name=name) config = utils.create_config() vol = K8sVolume(config=config, name=name, mount_path="/var/test", type="emptyDir") obj.add_volume(vol) self.assertEqual(1, len(obj.model.model["spec"]["volumes"])) self.assertEqual(1, len(obj.model.pod_spec.model["volumes"])) self.assertEqual(name, obj.model.model["spec"]["volumes"][0]["name"]) self.assertEqual(name, obj.model.pod_spec.model["volumes"][0]["name"])
def create_data_base(): con = connect(dbname=DBNAME, user=USER, host=HOST) dbname = 't_' + ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(7)) con.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT) cur = con.cursor() cur.execute('CREATE DATABASE ' + dbname) cur.close() con.close() db_dsn = 'postgresql://%s:password@%s/%s' % (USER, HOST, dbname) engine = create_engine(db_dsn) Base.metadata.create_all(engine) create_config(user=USER, host=HOST, dbname=dbname) return dbname, db_dsn
def test_list(self): count = 10 config = utils.create_config() if utils.is_reachable(config.api_host): for i in range(0, count): name = "yosecret-{0}".format(str(uuid.uuid4())) secret = utils.create_secret(name=name) secret.create() secret = utils.create_secret(name="yosecret") _list = secret.list() self.assertEqual(count + 1, len(_list)) # including service-account-token
def test_list(self): count = 10 config = utils.create_config() if utils.is_reachable(config.api_host): for i in range(0, count): name = "yosecret-{0}".format(str(uuid.uuid4())) secret = utils.create_secret(name=name) secret.create() secret = utils.create_secret(name="yosecret") _list = secret.list() self.assertGreaterEqual( count + 1, len(_list)) # including service-account-token on GCE
def test_pod_add_volume_hostpath(self): name = "yoname" obj = utils.create_pod(name=name) config = utils.create_config() vol = K8sVolume(config=config, name=name, mount_path="/var/test", type="hostPath") host_path = "/var/lib/docker" vol.set_path(host_path) obj.add_volume(vol) self.assertEqual(1, len(obj.model.model["spec"]["volumes"])) self.assertEqual(1, len(obj.model.pod_spec.model["volumes"])) self.assertEqual(name, obj.model.model["spec"]["volumes"][0]["name"]) self.assertEqual(name, obj.model.pod_spec.model["volumes"][0]["name"]) self.assertEqual(host_path, obj.model.model["spec"]["volumes"][0][vol.type]["path"]) self.assertEqual(host_path, obj.model.pod_spec.model["volumes"][0][vol.type]["path"])
def test_system_service(self): config = utils.create_config() config.namespace = 'kube-system' service = utils.create_service(config, name="kubernetes-dashboard") service.type = 'ClusterIP' service.add_port(port=80, target_port="k8s-dashport", name="kubernetes-dashboard", protocol="TCP") service.selector = {'k8s-app': "kubernetes-dashboard"} service.labels = { 'k8s-app': "kubernetes-dashboard", 'kubernetes.io/cluster-service': 'true' } if utils.is_reachable(service.config.api_host): with self.assertRaises(AlreadyExistsException): service.create() service.get() service.update()
def test_set_system_dockerconfigjson(self): name = "docker-registry" config = utils.create_config() config.namespace = 'kube-system' secret = utils.create_secret(config=config, name=name) data = { "auths": { "repo:port": { "auth": "authstring", "email": "*****@*****.**" } } } secret.dockerconfigjson = data self.assertEqual('kubernetes.io/.dockerconfigjson', secret.type) self.assertIn('.dockerconfigjson', secret.data) self.assertEqual(data, secret.dockerconfigjson) if utils.is_reachable(secret.config.api_host): try: secret.delete() except NotFoundException: pass s = secret.create() self.assertIsInstance(s, K8sSecret)
def test_init_invalid_type(self): name = "yoname" type = object() config = utils.create_config() with self.assertRaises(SyntaxError): K8sPersistentVolume(config=config, name=name, type=type)
def test_init_no_args(self): config = utils.create_config() with self.assertRaises(SyntaxError): K8sPersistentVolume(config=config)
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 test_get_by_labels_none_args(self): config = utils.create_config() with self.assertRaises(SyntaxError): K8sPod.get_by_labels(config=config)
def test_init_invalid_name(self): name = object() config = utils.create_config() with self.assertRaises(SyntaxError): K8sPersistentVolumeClaim(config=config, name=name)
def should_skip(): config = utils.create_config() return utils.assert_server_version( api_host=config.api_host, major=1, minor=4 )