summaryrefslogtreecommitdiffstats
path: root/app/test/fetch/cli_fetch/test_cli_fetch_instance_vnics.py
diff options
context:
space:
mode:
authorYaron Yogev <yaronyogev@gmail.com>2017-07-27 09:02:54 +0300
committerYaron Yogev <yaronyogev@gmail.com>2017-07-27 14:56:25 +0300
commit7e83d0876ddb84a45e130eeba28bc40ef53c074b (patch)
tree47d76239ae7658d87c66abd142df92709427e7dd /app/test/fetch/cli_fetch/test_cli_fetch_instance_vnics.py
parent378ecbd8947589b9cbb39013a0c2e2aa201e03bd (diff)
Calipso initial release for OPNFV
Change-Id: I7210c244b0c10fa80bfa8c77cb86c9d6ddf8bc88 Signed-off-by: Yaron Yogev <yaronyogev@gmail.com>
Diffstat (limited to 'app/test/fetch/cli_fetch/test_cli_fetch_instance_vnics.py')
-rw-r--r--app/test/fetch/cli_fetch/test_cli_fetch_instance_vnics.py111
1 files changed, 111 insertions, 0 deletions
diff --git a/app/test/fetch/cli_fetch/test_cli_fetch_instance_vnics.py b/app/test/fetch/cli_fetch/test_cli_fetch_instance_vnics.py
new file mode 100644
index 0000000..5a57b9c
--- /dev/null
+++ b/app/test/fetch/cli_fetch/test_cli_fetch_instance_vnics.py
@@ -0,0 +1,111 @@
+###############################################################################
+# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) #
+# and others #
+# #
+# All rights reserved. This program and the accompanying materials #
+# are made available under the terms of the Apache License, Version 2.0 #
+# which accompanies this distribution, and is available at #
+# http://www.apache.org/licenses/LICENSE-2.0 #
+###############################################################################
+from discover.fetchers.cli.cli_fetch_instance_vnics import CliFetchInstanceVnics
+from test.fetch.test_fetch import TestFetch
+from test.fetch.cli_fetch.test_data.cli_fetch_instance_vnics import *
+from unittest.mock import MagicMock
+
+
+class TestCliFetchInstanceVnics(TestFetch):
+
+ def setUp(self):
+ self.configure_environment()
+ self.fetcher = CliFetchInstanceVnics()
+ self.fetcher.set_env(self.env)
+
+ def test_get(self):
+ # store original methods
+ original_get_by_id = self.fetcher.inv.get_by_id
+ original_run_fetch_lines = self.fetcher.run_fetch_lines
+ original_get_vnics_from_dumpxml = self.fetcher.get_vnics_from_dumpxml
+
+ # mock methods
+ self.fetcher.inv.get_by_id = MagicMock(side_effect=[INSATNCE, COMPUTE_HOST])
+ self.fetcher.run_fetch_lines = MagicMock(return_value=INSTANCES_LIST)
+ self.fetcher.get_vnics_from_dumpxml = MagicMock(return_value=VNICS_FROM_DUMP_XML)
+
+ result = self.fetcher.get(VNICS_FOLDER['id'])
+
+ # reset methods
+ self.fetcher.inv.get_by_id = original_get_by_id
+ self.fetcher.run_fetch_lines = original_run_fetch_lines
+ self.fetcher.get_vnics_from_dumpxml = original_get_vnics_from_dumpxml
+
+ self.assertNotEqual(result, [], "Can't get vnics with VNICS folder id")
+
+ def test_get_without_instance(self):
+ # store original methods
+ original_get_by_id = self.fetcher.inv.get_by_id
+
+ # mock methods
+ self.fetcher.inv.get_by_id = MagicMock(return_value=[])
+
+ result = self.fetcher.get(VNICS_FOLDER['id'])
+
+ # reset methods
+ self.fetcher.inv.get_by_id = original_get_by_id
+
+ self.assertEqual(result, [], "Can't get empty array when the instance can't be found")
+
+ def test_get_without_host(self):
+ # store original methods
+ original_get_by_id = self.fetcher.inv.get_by_id
+
+ # mock methods
+ self.fetcher.inv.get_by_id = MagicMock(side_effect=[[], NETWORK_HOST])
+
+ result = self.fetcher.get(VNICS_FOLDER['id'])
+
+ # reset methods
+ self.fetcher.inv.get_by_id = original_get_by_id
+
+ self.assertEqual(result, [], "Can't get empty array when the host doesn't contain network host type")
+
+ def test_get_vnics_from_dumpxml(self):
+ # store original functions
+ original_run = self.fetcher.run
+ original_set_vnic_properties = self.fetcher.set_vnic_properties
+
+ # mock the functions
+ self.fetcher.run = MagicMock(return_value=DUMPXML)
+ self.fetcher.set_vnic_properties = MagicMock()
+
+ vnics = self.fetcher.get_vnics_from_dumpxml(ID, INSATNCE)
+ # reset functions
+ self.fetcher.run = original_run
+ self.fetcher.set_vnic_properties = original_set_vnic_properties
+
+ self.assertNotEqual(vnics, [], "Can't get vnics")
+
+ def test_get_vnics_from_dumpxml_with_empty_command_result(self):
+ # store original functions
+ original_run = self.fetcher.run
+
+ # mock the functions
+ self.fetcher.run = MagicMock(return_value=" ")
+
+ vnics = self.fetcher.get_vnics_from_dumpxml(ID, INSATNCE)
+ # reset functions
+ self.fetcher.run = original_run
+
+ self.assertEqual(vnics, [], "Can't get empty array when the dumpxml is empty")
+
+ def test_get_vnics_from_dumpxml_with_wrong_instance(self):
+ # store original functions
+ original_run = self.fetcher.run
+
+ # mock the functions
+ self.fetcher.run = MagicMock(return_value=WRONG_DUMPXML)
+
+ vnics = self.fetcher.get_vnics_from_dumpxml(ID, INSATNCE)
+ # reset functions
+ self.fetcher.run = original_run
+
+ self.assertEqual(vnics, [], "Can't get empty array when the instance is wrong") \ No newline at end of file