Skip to content

Commit

Permalink
Rename create_from_map to create_from_dict, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oz123 committed Mar 26, 2019
1 parent aa28bc7 commit cee4e49
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
34 changes: 34 additions & 0 deletions kubernetes/e2e_test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import unittest

import yaml
from kubernetes import utils, client
from kubernetes.e2e_test import base

Expand Down Expand Up @@ -42,6 +43,39 @@ def test_create_apps_deployment_from_yaml(self):
name="nginx-app", namespace="default",
body={})

def test_create_apps_deployment_from_yaml_string(self):
k8s_client = client.api_client.ApiClient(configuration=self.config)
with open(self.path_prefix + "apps-deployment.yaml") as f:
yaml_str = f.read()

utils.create_from_yaml(
k8s_client, yaml_str)

app_api = client.AppsV1beta1Api(k8s_client)
dep = app_api.read_namespaced_deployment(name="nginx-app",
namespace="default")
self.assertIsNotNone(dep)
app_api.delete_namespaced_deployment(
name="nginx-app", namespace="default",
body={})

def test_create_apps_deployment_from_yaml_obj(self):
k8s_client = client.api_client.ApiClient(configuration=self.config)
with open(self.path_prefix + "apps-deployment.yaml") as f:
yml_obj = yaml.safe_load(f)

utils.create_from_dict(
k8s_client, yml_obj)

app_api = client.AppsV1beta1Api(k8s_client)
dep = app_api.read_namespaced_deployment(name="nginx-app",
namespace="default")
self.assertIsNotNone(dep)
app_api.delete_namespaced_deployment(
name="nginx-app", namespace="default",
body={})


def test_create_extensions_deployment_from_yaml(self):
"""
Should be able to create an extensions/v1beta1 deployment.
Expand Down
6 changes: 3 additions & 3 deletions kubernetes/utils/create_from_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def create_from_yaml(
Perform an action from a yaml file. Pass True for verbose to
print confirmation information.
Input:
yaml_file: string. Contains yaml string or a path to yaml file.
yaml_file: string. Contains yaml string or a path to yaml file.
k8s_client: an ApiClient object, initialized with the client args.
verbose: If True, print confirmation from the create action.
Default is False.
Expand Down Expand Up @@ -61,11 +61,11 @@ def create_from_yaml(
yml_document_all = yaml.safe_load_all(yaml_file)
# Load all documents from a single YAML file
for yml_document in yml_document_all:
create_from_map(k8s_client, yml_document, verbose,
create_from_dict(k8s_client, yml_document, verbose,
**kwargs)


def create_from_map(k8s_client, yml_document, verbose=False, **kwargs):
def create_from_dict(k8s_client, yml_document, verbose=False, **kwargs):
# If it is a list type, will need to iterate its items
api_exceptions = []

Expand Down

0 comments on commit cee4e49

Please sign in to comment.