Skip to content

Commit cee4e49

Browse files
committed
Rename create_from_map to create_from_dict, add tests
1 parent aa28bc7 commit cee4e49

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

kubernetes/e2e_test/test_utils.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import unittest
1616

17+
import yaml
1718
from kubernetes import utils, client
1819
from kubernetes.e2e_test import base
1920

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

46+
def test_create_apps_deployment_from_yaml_string(self):
47+
k8s_client = client.api_client.ApiClient(configuration=self.config)
48+
with open(self.path_prefix + "apps-deployment.yaml") as f:
49+
yaml_str = f.read()
50+
51+
utils.create_from_yaml(
52+
k8s_client, yaml_str)
53+
54+
app_api = client.AppsV1beta1Api(k8s_client)
55+
dep = app_api.read_namespaced_deployment(name="nginx-app",
56+
namespace="default")
57+
self.assertIsNotNone(dep)
58+
app_api.delete_namespaced_deployment(
59+
name="nginx-app", namespace="default",
60+
body={})
61+
62+
def test_create_apps_deployment_from_yaml_obj(self):
63+
k8s_client = client.api_client.ApiClient(configuration=self.config)
64+
with open(self.path_prefix + "apps-deployment.yaml") as f:
65+
yml_obj = yaml.safe_load(f)
66+
67+
utils.create_from_dict(
68+
k8s_client, yml_obj)
69+
70+
app_api = client.AppsV1beta1Api(k8s_client)
71+
dep = app_api.read_namespaced_deployment(name="nginx-app",
72+
namespace="default")
73+
self.assertIsNotNone(dep)
74+
app_api.delete_namespaced_deployment(
75+
name="nginx-app", namespace="default",
76+
body={})
77+
78+
4579
def test_create_extensions_deployment_from_yaml(self):
4680
"""
4781
Should be able to create an extensions/v1beta1 deployment.

kubernetes/utils/create_from_yaml.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def create_from_yaml(
3030
Perform an action from a yaml file. Pass True for verbose to
3131
print confirmation information.
3232
Input:
33-
yaml_file: string. Contains yaml string or a path to yaml file.
33+
yaml_file: string. Contains yaml string or a path to yaml file.
3434
k8s_client: an ApiClient object, initialized with the client args.
3535
verbose: If True, print confirmation from the create action.
3636
Default is False.
@@ -61,11 +61,11 @@ def create_from_yaml(
6161
yml_document_all = yaml.safe_load_all(yaml_file)
6262
# Load all documents from a single YAML file
6363
for yml_document in yml_document_all:
64-
create_from_map(k8s_client, yml_document, verbose,
64+
create_from_dict(k8s_client, yml_document, verbose,
6565
**kwargs)
6666

6767

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

0 commit comments

Comments
 (0)