diff options
author | Ćukasz 'sil2100' Zemczak <lukasz.zemczak@ubuntu.com> | 2017-09-04 10:27:07 +0200 |
---|---|---|
committer | usd-importer <ubuntu-server@lists.ubuntu.com> | 2017-09-04 09:38:24 +0000 |
commit | e919bdd14e48919244da9e499070fb64377993e5 (patch) | |
tree | 33c260c7c99410ac94d5f265fc506cc0b40bb6e4 /tests/protocol/test_hostplugin.py | |
parent | 70c0ea1ac879b2e1cba0a8edb1f3fbe82652413b (diff) | |
parent | 3a1d96a77ccaf023256d16183428e3d895f8a051 (diff) | |
download | vyos-walinuxagent-e919bdd14e48919244da9e499070fb64377993e5.tar.gz vyos-walinuxagent-e919bdd14e48919244da9e499070fb64377993e5.zip |
Import patches-applied version 2.2.16-0ubuntu1 to applied/ubuntu/artful-proposed
Imported using git-ubuntu import.
Changelog parent: 70c0ea1ac879b2e1cba0a8edb1f3fbe82652413b
Unapplied parent: 3a1d96a77ccaf023256d16183428e3d895f8a051
New changelog entries:
* New upstream release (LP: #1714299).
Diffstat (limited to 'tests/protocol/test_hostplugin.py')
-rw-r--r-- | tests/protocol/test_hostplugin.py | 61 |
1 files changed, 6 insertions, 55 deletions
diff --git a/tests/protocol/test_hostplugin.py b/tests/protocol/test_hostplugin.py index b18b691..74f7f24 100644 --- a/tests/protocol/test_hostplugin.py +++ b/tests/protocol/test_hostplugin.py @@ -146,6 +146,7 @@ class TestHostPlugin(AgentTestCase): test_goal_state = wire.GoalState(WireProtocolData(DATA_FILE).goal_state) status = restapi.VMStatus(status="Ready", message="Guest Agent is running") + wire.HostPluginProtocol.set_default_channel(False) with patch.object(wire.HostPluginProtocol, "ensure_initialized", return_value=True): @@ -173,6 +174,7 @@ class TestHostPlugin(AgentTestCase): test_goal_state = wire.GoalState(WireProtocolData(DATA_FILE).goal_state) status = restapi.VMStatus(status="Ready", message="Guest Agent is running") + wire.HostPluginProtocol.set_default_channel(False) with patch.object(wire.StatusBlob, "upload", return_value=False): @@ -211,6 +213,8 @@ class TestHostPlugin(AgentTestCase): bytearray(faux_status, encoding='utf-8')) with patch.object(restutil, "http_request") as patch_http: + patch_http.return_value = Mock(status=httpclient.OK) + wire_protocol_client.get_goal_state = Mock(return_value=test_goal_state) plugin = wire_protocol_client.get_host_plugin() @@ -224,61 +228,6 @@ class TestHostPlugin(AgentTestCase): test_goal_state, exp_method, exp_url, exp_data) - def test_read_response_error(self): - """ - Validate the read_response_error method handles encoding correctly - """ - responses = ['message', b'message', '\x80message\x80'] - response = MagicMock() - response.status = 'status' - response.reason = 'reason' - with patch.object(response, 'read') as patch_response: - for s in responses: - patch_response.return_value = s - result = hostplugin.HostPluginProtocol.read_response_error(response) - self.assertTrue('[status: reason]' in result) - self.assertTrue('message' in result) - - def test_read_response_bytes(self): - response_bytes = '7b:0a:20:20:20:20:22:65:72:72:6f:72:43:6f:64:65:22:' \ - '3a:20:22:54:68:65:20:62:6c:6f:62:20:74:79:70:65:20:' \ - '69:73:20:69:6e:76:61:6c:69:64:20:66:6f:72:20:74:68:' \ - '69:73:20:6f:70:65:72:61:74:69:6f:6e:2e:22:2c:0a:20:' \ - '20:20:20:22:6d:65:73:73:61:67:65:22:3a:20:22:c3:af:' \ - 'c2:bb:c2:bf:3c:3f:78:6d:6c:20:76:65:72:73:69:6f:6e:' \ - '3d:22:31:2e:30:22:20:65:6e:63:6f:64:69:6e:67:3d:22:' \ - '75:74:66:2d:38:22:3f:3e:3c:45:72:72:6f:72:3e:3c:43:' \ - '6f:64:65:3e:49:6e:76:61:6c:69:64:42:6c:6f:62:54:79:' \ - '70:65:3c:2f:43:6f:64:65:3e:3c:4d:65:73:73:61:67:65:' \ - '3e:54:68:65:20:62:6c:6f:62:20:74:79:70:65:20:69:73:' \ - '20:69:6e:76:61:6c:69:64:20:66:6f:72:20:74:68:69:73:' \ - '20:6f:70:65:72:61:74:69:6f:6e:2e:0a:52:65:71:75:65:' \ - '73:74:49:64:3a:63:37:34:32:39:30:63:62:2d:30:30:30:' \ - '31:2d:30:30:62:35:2d:30:36:64:61:2d:64:64:36:36:36:' \ - '61:30:30:30:22:2c:0a:20:20:20:20:22:64:65:74:61:69:' \ - '6c:73:22:3a:20:22:22:0a:7d'.split(':') - expected_response = '[status: reason] {\n "errorCode": "The blob ' \ - 'type is invalid for this operation.",\n ' \ - '"message": "<?xml version="1.0" ' \ - 'encoding="utf-8"?>' \ - '<Error><Code>InvalidBlobType</Code><Message>The ' \ - 'blob type is invalid for this operation.\n' \ - 'RequestId:c74290cb-0001-00b5-06da-dd666a000",' \ - '\n "details": ""\n}' - - response_string = ''.join(chr(int(b, 16)) for b in response_bytes) - response = MagicMock() - response.status = 'status' - response.reason = 'reason' - with patch.object(response, 'read') as patch_response: - patch_response.return_value = response_string - result = hostplugin.HostPluginProtocol.read_response_error(response) - self.assertEqual(result, expected_response) - try: - raise HttpError("{0}".format(result)) - except HttpError as e: - self.assertTrue(result in ustr(e)) - def test_no_fallback(self): """ Validate fallback to upload status using HostGAPlugin is not happening @@ -318,6 +267,8 @@ class TestHostPlugin(AgentTestCase): bytearray(faux_status, encoding='utf-8')) with patch.object(restutil, "http_request") as patch_http: + patch_http.return_value = Mock(status=httpclient.OK) + with patch.object(wire.HostPluginProtocol, "get_api_versions") as patch_get: patch_get.return_value = api_versions |