def test_should_fail_when_logical_interconnect_not_found(self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.logical_interconnects.get_by_name.return_value = None

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(self.PARAMS_QOS_AGGREG_CONFIG)
        mock_ansible_module.return_value = mock_ansible_instance

        LogicalInterconnectModule().run()

        mock_ansible_instance.fail_json.assert_called_once_with(
            msg=LOGICAL_INTERCONNECT_NOT_FOUND
        )

        @mock.patch.object(OneViewClient, 'from_json_file')
        @mock.patch('oneview_logical_interconnect.AnsibleModule')
        def test_should_fail_when_update_qos_raises_exception(self, mock_ansible_module,
                                                              mock_ov_client_from_json_file):
            mock_ov_instance = mock.Mock()
            mock_ov_instance.logical_interconnects.get_by_name.return_value = LOGICAL_INTERCONNECT
            mock_ov_instance.logical_interconnects.get_qos_aggregated_configuration.return_value = self.qos_config
            mock_ov_instance.logical_interconnects.update_qos_aggregated_configuration.side_effect = \
                Exception(FAKE_MSG_ERROR)

            mock_ov_client_from_json_file.return_value = mock_ov_instance
            mock_ansible_instance = create_ansible_mock(self.PARAMS_QOS_AGGREG_CONFIG)
            mock_ansible_module.return_value = mock_ansible_instance

            self.assertRaises(Exception, LogicalInterconnectModule().run())

            mock_ansible_instance.fail_json.assert_called_once_with(
                msg=FAKE_MSG_ERROR
            )
def define_mocks(mock_ov_client_from_json_file, mock_ansible_module, params):
    mock_ov_instance = mock.Mock()
    mock_ov_client_from_json_file.return_value = mock_ov_instance

    mock_ansible_instance = create_ansible_mock(params)
    mock_ansible_module.return_value = mock_ansible_instance
    return mock_ov_instance, mock_ansible_instance
示例#3
0
    def test_should_get_by_name_with_options(self, mock_ansible_module,
                                             mock_ov_from_file):
        switches = [SWITCH]
        environmental_configuration = dict(calibratedMaxPower=0,
                                           capHistorySupported=False)

        mock_ov_instance = mock.Mock()
        mock_ov_instance.switches.get_by.return_value = switches
        mock_ov_instance.switches.get_environmental_configuration.return_value = environmental_configuration
        mock_ov_from_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(
            PARAMS_GET_BY_NAME_WITH_OPTIONS)
        mock_ansible_module.return_value = mock_ansible_instance

        SwitchFactsModule().run()

        mock_ov_instance.switches.get_by.assert_called_once_with(
            'name', SWITCH_NAME)
        mock_ov_instance.switches.get_environmental_configuration.assert_called_once_with(
            id_or_uri=SWITCH_URI)

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(
                switches=switches,
                switch_environmental_configuration=environmental_configuration)
        )
    def test_should_get_without_ethernet(self, mock_ansible_module,
                                         mock_ov_from_file):
        logical_downlinks = [LOGICAL_DOWNLINK]
        logical_downlinks_without_ethernet = []

        mock_ov_instance = mock.Mock()
        mock_ov_instance.logical_downlinks.get_by.return_value = logical_downlinks
        mock_ov_instance.logical_downlinks.get_without_ethernet.return_value = logical_downlinks_without_ethernet

        mock_ov_from_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(
            PARAMS_FOR_GET_WITHOUT_ETHERNET)
        mock_ansible_module.return_value = mock_ansible_instance

        LogicalDownlinksFactsModule().run()

        mock_ov_instance.logical_downlinks.get_by.assert_called_once_with(
            'name', LOGICAL_DOWNLINK_NAME)
        mock_ov_instance.logical_downlinks.get_without_ethernet.assert_called_once_with(
            id_or_uri=LOGICAL_DOWNLINK_URI)

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(
                logical_downlinks=logical_downlinks_without_ethernet))
    def test_should_get_enclosure_group_by_name_with_options(self, mock_ansible_module,
                                                             mock_ov_client_from_json_file):
        configuration_script = "echo 'test'"

        mock_ov_instance = mock.Mock()
        mock_ov_instance.enclosure_groups.get_by.return_value = ENCLOSURE_GROUPS
        mock_ov_instance.enclosure_groups.get_script.return_value = configuration_script

        mock_ov_client_from_json_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(PARAMS_GET_BY_NAME_WITH_OPTIONS)
        mock_ansible_module.return_value = mock_ansible_instance

        EnclosureGroupFactsModule().run()

        mock_ov_instance.enclosure_groups.get_by.assert_called_once_with('name', ENCLOSURE_GROUP_NAME)
        mock_ov_instance.enclosure_groups.get_script.assert_called_once_with(id_or_uri=ENCLOSURE_GROUP_URI)

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(
                enclosure_groups=ENCLOSURE_GROUPS,
                enclosure_group_script=configuration_script
            )
        )
    def test_should_fail_when_get_by_name_raises_exception(self, mock_ansible_module, mock_ov_from_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.managed_sans.get_by_name.side_effect = Exception(ERROR_MSG)
        mock_ov_from_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(PARAMS_GET_BY_NAME)
        mock_ansible_module.return_value = mock_ansible_instance

        ManagedSanFactsModule().run()

        mock_ansible_instance.fail_json.assert_called_once_with(msg=ERROR_MSG)
    def test_should_fail_when_get_by_name_raises_exception(self, mock_ansible_module, mock_ov_from_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.unmanaged_devices.get_by.side_effect = Exception(ERROR_MSG)

        mock_ov_from_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(PARAMS_FOR_PRESENT)
        mock_ansible_module.return_value = mock_ansible_instance

        UnmanagedDeviceModule().run()

        mock_ansible_instance.fail_json.assert_called_once_with(msg=ERROR_MSG)
    def test_should_fail_when_get_all_raises_error(self, mock_ansible_module, mock_ov_from_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.tasks.get_all.side_effect = Exception(ERROR_MSG)
        mock_ov_from_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(PARAMS_GET_ALL)
        mock_ansible_module.return_value = mock_ansible_instance

        TaskFactsModule().run()

        mock_ansible_instance.fail_json.assert_called_once_with(msg=ERROR_MSG)
    def test_should_load_config_from_file(self, mock_ansible_module, mock_ov_client_from_env_vars,
                                          mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock({'config': 'config.json'})
        mock_ansible_module.return_value = mock_ansible_instance

        SwitchModule()

        mock_ov_client_from_json_file.assert_called_once_with('config.json')
        mock_ov_client_from_env_vars.not_been_called()
示例#10
0
    def test_should_fail_when_get_by_name_raises_exception(self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.logical_enclosures.get_by.side_effect = Exception(ERROR_MSG)

        mock_ov_client_from_json_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(PARAMS_GET_BY_NAME)
        mock_ansible_module.return_value = mock_ansible_instance

        LogicalEnclosureFactsModule().run()

        mock_ansible_instance.fail_json.assert_called_once()
    def test_should_fail_when_get_all_raises_error(self, mock_ansible_module,
                                                   mock_ov_from_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.tasks.get_all.side_effect = Exception(ERROR_MSG)
        mock_ov_from_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(PARAMS_GET_ALL)
        mock_ansible_module.return_value = mock_ansible_instance

        TaskFactsModule().run()

        mock_ansible_instance.fail_json.assert_called_once_with(msg=ERROR_MSG)
    def test_should_fail_when_get_all_raises_exception(self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.ethernet_networks.get_all.side_effect = Exception(ERROR_MSG)

        mock_ov_client_from_json_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(PARAMS_GET_ALL)
        mock_ansible_module.return_value = mock_ansible_instance

        EthernetNetworkFactsModule().run()

        mock_ansible_instance.fail_json.assert_called_once()
示例#13
0
    def test_should_get_all(self, mock_ansible_module, mock_ov_from_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.switches.get_all.return_value = ALL_SWITCHES
        mock_ov_from_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(PARAMS_GET_ALL)
        mock_ansible_module.return_value = mock_ansible_instance

        SwitchFactsModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False, ansible_facts=dict(switches=ALL_SWITCHES))
    def test_should_load_config_from_environment(self, mock_ansible_module, mock_ov_client_from_env_vars,
                                                 mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()

        mock_ov_client_from_env_vars.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock({'config': None})
        mock_ansible_module.return_value = mock_ansible_instance

        TaskFactsModule()

        mock_ov_client_from_env_vars.assert_called_once()
        mock_ov_client_from_json_file.not_been_called()
    def test_should_load_config_from_environment(self, mock_ansible_module, mock_ov_client_from_env_vars,
                                                 mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()

        mock_ov_client_from_env_vars.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock({'config': None})
        mock_ansible_module.return_value = mock_ansible_instance

        LogicalInterconnectModule()

        mock_ov_client_from_env_vars.assert_called_once()
        mock_ov_client_from_json_file.not_been_called()
    def test_should_update_firmware_when_spp_uri_set(self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.logical_interconnects.get_by_name.return_value = LOGICAL_INTERCONNECT
        mock_ov_instance.logical_interconnects.install_firmware.return_value = self.response

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(self.PARAMS_FIRMWARE_WITH_SPP_URI)
        mock_ansible_module.return_value = mock_ansible_instance

        LogicalInterconnectModule().run()

        mock_ov_instance.logical_interconnects.install_firmware.assert_called_once_with(self.expected_data, mock.ANY)
    def test_should_fail_when_logical_interconnect_not_found(self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.logical_interconnects.get_by_name.return_value = None

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(self.PARAMS_FIRMWARE_WITH_SPP_URI)
        mock_ansible_module.return_value = mock_ansible_instance

        LogicalInterconnectModule().run()

        mock_ansible_instance.fail_json.assert_called_once_with(
            msg=LOGICAL_INTERCONNECT_NOT_FOUND
        )
    def test_should_do_nothing_when_not_exist(self, mock_ansible_module, mock_ov_from_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.unmanaged_devices.get_by.return_value = []

        mock_ov_from_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(PARAMS_FOR_ABSENT)
        mock_ansible_module.return_value = mock_ansible_instance

        UnmanagedDeviceModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False,
            msg=NOTHING_TO_DO
        )
    def test_should_get_all(self, mock_ansible_module, mock_ov_from_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.managed_sans.get_all.return_value = ALL_MANAGED_SANS
        mock_ov_from_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(PARAMS_GET_ALL)
        mock_ansible_module.return_value = mock_ansible_instance

        ManagedSanFactsModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(managed_sans=ALL_MANAGED_SANS)
        )
    def test_should_do_nothing_when_no_changes(self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.logical_interconnects.get_by_name.return_value = LOGICAL_INTERCONNECT
        mock_ov_instance.logical_interconnects.get_qos_aggregated_configuration.return_value = self.qos_config

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(self.PARAMS_QOS_AGGREG_NO_CHANGES)
        mock_ansible_module.return_value = mock_ansible_instance

        LogicalInterconnectModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False,
            msg=LOGICAL_INTERCONNECT_NO_CHANGES_PROVIDED)
示例#21
0
    def test_should_fail_when_get_all_raises_exception(
            self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.ethernet_networks.get_all.side_effect = Exception(
            ERROR_MSG)

        mock_ov_client_from_json_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(PARAMS_GET_ALL)
        mock_ansible_module.return_value = mock_ansible_instance

        EthernetNetworkFactsModule().run()

        mock_ansible_instance.fail_json.assert_called_once()
    def test_should_get_all(self, mock_ansible_module, mock_ov_from_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.switches.get_all.return_value = ALL_SWITCHES
        mock_ov_from_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(PARAMS_GET_ALL)
        mock_ansible_module.return_value = mock_ansible_instance

        SwitchFactsModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(switches=ALL_SWITCHES)
        )
    def test_should_do_nothing_when_no_changes(self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.logical_interconnects.get_by_name.return_value = LOGICAL_INTERCONNECT
        mock_ov_instance.logical_interconnects.update_ethernet_settings.return_value = LOGICAL_INTERCONNECT

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(self.PARAMS_ETHERNET_SETTINGS_NO_CHANGES)
        mock_ansible_module.return_value = mock_ansible_instance

        LogicalInterconnectModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False,
            msg=LOGICAL_INTERCONNECT_NO_CHANGES_PROVIDED)
    def test_should_fail_when_compliance_raises_exception(self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.logical_interconnects.get_by_name.return_value = LOGICAL_INTERCONNECT
        mock_ov_instance.logical_interconnects.update_compliance.side_effect = Exception(FAKE_MSG_ERROR)

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(self.PARAMS_COMPLIANCE)
        mock_ansible_module.return_value = mock_ansible_instance

        self.assertRaises(Exception, LogicalInterconnectModule().run())

        mock_ansible_instance.fail_json.assert_called_once_with(
            msg=FAKE_MSG_ERROR
        )
    def test_get_all(self, mock_ansible_module, mock_ov_from_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.tasks.get_all.return_value = ALL_TASKS
        mock_ov_from_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(PARAMS_GET_ALL)
        mock_ansible_module.return_value = mock_ansible_instance

        TaskFactsModule().run()

        mock_ov_instance.tasks.get_all.assert_called_once_with()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False, ansible_facts=dict(tasks=ALL_TASKS))
示例#26
0
    def test_should_get_all_logical_enclosure(self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.logical_enclosures.get_all.return_value = [LOGICAL_ENCLOSURE]

        mock_ov_client_from_json_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(PARAMS_GET_ALL)
        mock_ansible_module.return_value = mock_ansible_instance

        LogicalEnclosureFactsModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(logical_enclosures=([LOGICAL_ENCLOSURE]))
        )
    def test_should_fail_when_get_by_raises_exception(self,
                                                      mock_ansible_module,
                                                      mock_ov_from_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.logical_downlinks.get_by.side_effect = Exception(
            ERROR_MSG)

        mock_ov_from_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(PARAMS_FOR_GET_BY_NAME)
        mock_ansible_module.return_value = mock_ansible_instance

        LogicalDownlinksFactsModule().run()

        mock_ansible_instance.fail_json.assert_called_once_with(msg=ERROR_MSG)
    def test_should_do_nothing_when_no_changes(self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.logical_interconnects.get_by_name.return_value = LOGICAL_INTERCONNECT
        mock_ov_instance.logical_interconnects.get_port_monitor.return_value = self.monitor_config
        mock_ov_instance.logical_interconnects.update_port_monitor.return_value = self.monitor_config

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(self.PARAMS_PORT_MONITOR_CONFIGURATION_NO_CHANGES)
        mock_ansible_module.return_value = mock_ansible_instance

        LogicalInterconnectModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False,
            msg=LOGICAL_INTERCONNECT_NO_CHANGES_PROVIDED)
示例#29
0
    def test_should_get_enet_by_name(self, mock_ansible_module,
                                     mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.ethernet_networks.get_by.return_value = PRESENT_ENETS

        mock_ov_client_from_json_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(PARAMS_GET_BY_NAME)
        mock_ansible_module.return_value = mock_ansible_instance

        EthernetNetworkFactsModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(ethernet_networks=(PRESENT_ENETS)))
    def test_should_fail_when_ethernet_network_not_found(self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.logical_interconnects.get_by_name.return_value = LOGICAL_INTERCONNECT
        mock_ov_instance.ethernet_networks.get_by.side_effect = [[{'uri': '/path/1'}], []]
        mock_ov_instance.logical_interconnects.update_internal_networks.return_value = {}

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(self.PARAMS_INTERNAL_NETWORKS)
        mock_ansible_module.return_value = mock_ansible_instance

        LogicalInterconnectModule().run()

        mock_ansible_instance.fail_json.assert_called_once_with(
            msg=LOGICAL_INTERCONNECT_ETH_NETWORK_NOT_FOUND + "Network Name 2"
        )
    def test_should_fail_when_get_script_raises_exception(self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.enclosures.get_by.return_value = PRESENT_ENCLOSURES
        mock_ov_instance.enclosures.get_script.side_effect = Exception(ERROR_MSG)
        mock_ov_instance.enclosures.get_utilization.return_value = ENCLOSURE_UTILIZATION
        mock_ov_instance.enclosures.get_environmental_configuration.return_value = ENCLOSURE_ENVIRONMENTAL_CONFIG

        mock_ov_client_from_json_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(PARAMS_GET_BY_NAME_WITH_OPTIONS)
        mock_ansible_module.return_value = mock_ansible_instance

        EnclosureFactsModule().run()

        mock_ansible_instance.fail_json.assert_called_once()
    def test_should_get_enet_by_name(self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.ethernet_networks.get_by.return_value = PRESENT_ENETS

        mock_ov_client_from_json_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(PARAMS_GET_BY_NAME)
        mock_ansible_module.return_value = mock_ansible_instance

        EthernetNetworkFactsModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(ethernet_networks=(PRESENT_ENETS))
        )
    def test_get_all_with_filter(self, mock_ansible_module, mock_ov_from_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.tasks.get_all.return_value = ALL_TASKS
        mock_ov_from_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(PARAMS_GET_ALL_WITH_FILTER)
        mock_ansible_module.return_value = mock_ansible_instance

        TaskFactsModule().run()

        mock_ov_instance.tasks.get_all.assert_called_once_with(
            filter=FILTER_BY_ASSOCIATED_RESOURCE_NAME)

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False, ansible_facts=dict(tasks=ALL_TASKS))
    def test_should_update_ethernet_with_merged_data(self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.logical_interconnects.get_by_name.return_value = LOGICAL_INTERCONNECT
        mock_ov_instance.logical_interconnects.update_ethernet_settings.return_value = LOGICAL_INTERCONNECT

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(self.PARAMS_ETHERNET_SETTINGS)
        mock_ansible_module.return_value = mock_ansible_instance

        LogicalInterconnectModule().run()

        expected_uri = '/rest/logical-interconnects/id'
        expected_data = {'enableIgmpSnooping': True, 'macRefreshInterval': 7}
        mock_ov_instance.logical_interconnects.update_ethernet_settings.assert_called_once_with(expected_uri,
                                                                                                expected_data)
示例#35
0
    def test_get_all(self, mock_ansible_module, mock_ov_from_file):
        mock_ov_instance = mock.Mock()
        mock_ov_from_file.return_value = mock_ov_instance

        unmanaged_devices = [UNMANAGED_DEVICE]
        mock_ov_instance.unmanaged_devices.get_all.return_value = unmanaged_devices

        mock_ansible_instance = create_ansible_mock(PARAMS_GET_ALL)
        mock_ansible_module.return_value = mock_ansible_instance

        UnmanagedDeviceFactsModule().run()

        mock_ov_instance.unmanaged_devices.get_all.assert_called_once()
        mock_ansible_instance.exit_json.assert_called_once_with(
            ansible_facts=dict(unmanaged_devices=unmanaged_devices))
    def test_should_generate_interconnect_fib(self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.logical_interconnects.get_by_name.return_value = LOGICAL_INTERCONNECT
        mock_ov_instance.logical_interconnects.create_forwarding_information_base.return_value = self.response_body

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(self.PARAMS_GENERATE_FIB)
        mock_ansible_module.return_value = mock_ansible_instance

        LogicalInterconnectModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=True,
            msg=self.status,
            ansible_facts=dict(interconnect_fib=self.response_body)
        )
    def test_should_return_to_a_consistent_state(self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.logical_interconnects.get_by_name.return_value = LOGICAL_INTERCONNECT
        mock_ov_instance.logical_interconnects.update_compliance.return_value = LOGICAL_INTERCONNECT

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(self.PARAMS_COMPLIANCE)
        mock_ansible_module.return_value = mock_ansible_instance

        LogicalInterconnectModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=True,
            msg=LOGICAL_INTERCONNECT_CONSISTENT,
            ansible_facts=dict(logical_interconnect=LOGICAL_INTERCONNECT)
        )
    def test_should_fail_when_generate_fib_raises_exception(self, mock_ansible_module,
                                                            mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.logical_interconnects.get_by_name.return_value = LOGICAL_INTERCONNECT
        mock_ov_instance.logical_interconnects.create_forwarding_information_base.side_effect = \
            Exception(FAKE_MSG_ERROR)

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(self.PARAMS_GENERATE_FIB)
        mock_ansible_module.return_value = mock_ansible_instance

        self.assertRaises(Exception, LogicalInterconnectModule().run())

        mock_ansible_instance.fail_json.assert_called_once_with(
            msg=FAKE_MSG_ERROR
        )
    def test_get_all_with_filter(self, mock_ansible_module, mock_ov_from_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.tasks.get_all.return_value = ALL_TASKS
        mock_ov_from_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(PARAMS_GET_ALL_WITH_FILTER)
        mock_ansible_module.return_value = mock_ansible_instance

        TaskFactsModule().run()

        mock_ov_instance.tasks.get_all.assert_called_once_with(filter=FILTER_BY_ASSOCIATED_RESOURCE_NAME)

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(tasks=ALL_TASKS)
        )
    def test_get_all(self, mock_ansible_module, mock_ov_from_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.tasks.get_all.return_value = ALL_TASKS
        mock_ov_from_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(PARAMS_GET_ALL)
        mock_ansible_module.return_value = mock_ansible_instance

        TaskFactsModule().run()

        mock_ov_instance.tasks.get_all.assert_called_once_with()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(tasks=ALL_TASKS)
        )
    def test_should_get_all_enclosure_group(self, mock_ansible_module,
                                            mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.enclosure_groups.get_all.return_value = ENCLOSURE_GROUPS

        mock_ov_client_from_json_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(PARAMS_GET_ALL)
        mock_ansible_module.return_value = mock_ansible_instance

        EnclosureGroupFactsModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(enclosure_groups=ENCLOSURE_GROUPS)
        )
    def test_should_update_configuration(self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.logical_interconnects.get_by_name.return_value = LOGICAL_INTERCONNECT
        mock_ov_instance.logical_interconnects.update_configuration.return_value = LOGICAL_INTERCONNECT

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(self.PARAMS_CONFIGURATION)
        mock_ansible_module.return_value = mock_ansible_instance

        LogicalInterconnectModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=True,
            msg=LOGICAL_INTERCONNECT_CONFIGURATION_UPDATED,
            ansible_facts=dict(logical_interconnect=LOGICAL_INTERCONNECT)
        )
    def test_should_install_firmware(self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.logical_interconnects.get_by_name.return_value = LOGICAL_INTERCONNECT
        mock_ov_instance.logical_interconnects.install_firmware.return_value = self.response

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(self.PARAMS_FIRMWARE_WITH_SPP_NAME)
        mock_ansible_module.return_value = mock_ansible_instance

        LogicalInterconnectModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=True,
            msg=LOGICAL_INTERCONNECT_FIRMWARE_INSTALLED,
            ansible_facts=dict(li_firmware=self.response)
        )