Fixing patch_* commands execution

This patch fixes the following error during
patch_* calls:

UnboundLocalError: local variable 'r' referenced before assignment

Change-Id: I0d96e0099b343d4473e1d3bd1dbbaed03c4c1720
This commit is contained in:
Andrey 2016-08-26 13:09:42 +00:00
parent c8852d99a5
commit a2169399ae
2 changed files with 27 additions and 1 deletions

View File

@ -127,6 +127,11 @@ class RESTClientObject(object):
if method in ['POST', 'PUT', 'PATCH']:
if query_params:
url += '?' + urlencode(query_params)
if headers['Content-Type'] == 'application/json-patch+json':
headers['Content-Type'] = 'application/strategic-merge-patch+json'
r = self.agent(url).request(method, url,
body=json.dumps(body),
headers=headers)
if headers['Content-Type'] == 'application/json':
r = self.agent(url).request(method, url,
body=json.dumps(body),

View File

@ -92,7 +92,8 @@ class TestK8sclient(base.TestCase):
'metadata': {'labels': {'name': 'frontend'},
'name': 'frontend',
'resourceversion': 'v1'},
'spec': {'ports': [{'port': 80,
'spec': {'ports': [{'name': 'port',
'port': 80,
'protocol': 'TCP',
'targetPort': 80}],
'selector': {'name': 'frontend'}}}
@ -107,6 +108,16 @@ class TestK8sclient(base.TestCase):
self.assertEqual('frontend', resp.metadata.name)
self.assertTrue(resp.status)
service_manifest['spec']['ports'] = [{'name': 'new',
'port': 8080,
'protocol': 'TCP',
'targetPort': 8080}]
resp = api.patch_namespaced_service(body=service_manifest,
name='frontend',
namespace='default')
self.assertEqual(2, len(resp.spec.ports))
self.assertTrue(resp.status)
resp = api.delete_namespaced_service(name='frontend',
namespace='default')
@ -172,6 +183,10 @@ class TestK8sclient(base.TestCase):
name='test-configmap', namespace='default')
self.assertEqual('test-configmap', resp.metadata.name)
test_configmap['data']['config.json'] = "{}"
resp = api.patch_namespaced_config_map(
name='test-configmap', namespace='default', body=test_configmap)
resp = api.delete_namespaced_config_map(
name='test-configmap', body={}, namespace='default')
@ -209,6 +224,12 @@ class TestK8sclientBeta(base.TestCase):
self.assertEqual('test-deployment', resp.metadata.name)
self.assertEqual(2, resp.spec.replicas)
deployment_manifest['spec']['replicas'] = 1
resp = api.patch_namespaced_deployment(
name='test-deployment', namespace='default',
body=deployment_manifest)
self.assertEqual(1, resp.spec.replicas)
resp = api.delete_namespaced_deployment(
name='test-deployment', body={}, namespace='default')