From 7e83d0876ddb84a45e130eeba28bc40ef53c074b Mon Sep 17 00:00:00 2001 From: Yaron Yogev Date: Thu, 27 Jul 2017 09:02:54 +0300 Subject: Calipso initial release for OPNFV Change-Id: I7210c244b0c10fa80bfa8c77cb86c9d6ddf8bc88 Signed-off-by: Yaron Yogev --- .../cli_fetch/test_cli_fetch_instance_vnics.py | 111 +++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 app/test/fetch/cli_fetch/test_cli_fetch_instance_vnics.py (limited to 'app/test/fetch/cli_fetch/test_cli_fetch_instance_vnics.py') 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 -- cgit 1.2.3-korg