Exemplo n.º 1
0
    def test_should_fail_when_logical_interconnect_not_found(self):
        self.resource.get_by_name.return_value = None

        self.mock_ansible_module.params = PARAMS_COMPLIANCE

        LogicalInterconnectModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=LogicalInterconnectModule.MSG_NOT_FOUND)
Exemplo n.º 2
0
    def test_should_update_firmware_when_spp_uri_set(self):
        self.resource.data = LOGICAL_INTERCONNECT
        self.resource.install_firmware.return_value = self.response

        self.mock_ansible_module.params = PARAMS_FIRMWARE_WITH_SPP_URI

        LogicalInterconnectModule().run()

        self.resource.install_firmware.assert_called_once_with(self.expected_data)
Exemplo n.º 3
0
    def test_should_update_ethernet_with_merged_data(self):
        self.resource.data = LOGICAL_INTERCONNECT
        self.resource.update_ethernet_settings.return_value = LOGICAL_INTERCONNECT

        self.mock_ansible_module.params = PARAMS_ETHERNET_SETTINGS

        LogicalInterconnectModule().run()

        expected_data = {'enableIgmpSnooping': True, 'macRefreshInterval': 7}
        self.resource.update_ethernet_settings.assert_called_once_with(expected_data)
Exemplo n.º 4
0
    def test_should_install_firmware_when_spp_name_set(self):
        self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
        self.resource.install_firmware.return_value = self.response

        self.mock_ansible_module.params = self.PARAMS_FIRMWARE_WITH_SPP_NAME

        LogicalInterconnectModule().run()

        self.resource.install_firmware.assert_called_once_with(
            self.expected_data, mock.ANY)
Exemplo n.º 5
0
    def test_should_fail_when_settings_are_invalid(self):
        self.mock_ansible_module.params = dict(
            config='config.json',
            state='settings_updated',
            data=dict(name='Name of the Logical Interconnect'))

        LogicalInterconnectModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(
            msg=LogicalInterconnectModule.MSG_NO_OPTIONS_PROVIDED)
    def test_should_do_nothing_when_no_changes_ethernet_settings(self):
        self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
        self.resource.update_ethernet_settings.return_value = LOGICAL_INTERCONNECT

        self.mock_ansible_module.params = PARAMS_ETHERNET_SETTINGS_NO_CHANGES

        LogicalInterconnectModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=LogicalInterconnectModule.MSG_NO_CHANGES_PROVIDED)
    def test_should_do_nothing_when_no_changes_qos(self):
        self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
        self.resource.get_qos_aggregated_configuration.return_value = self.qos_config

        self.mock_ansible_module.params = PARAMS_QOS_AGGREG_NO_CHANGES

        LogicalInterconnectModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=LogicalInterconnectModule.MSG_NO_CHANGES_PROVIDED)
Exemplo n.º 8
0
    def test_should_fail_when_ethernet_network_not_found(self):
        self.resource.data = LOGICAL_INTERCONNECT
        self.mock_ov_client.ethernet_networks.get_by.side_effect = [[{'uri': '/path/1'}], []]
        self.resource.update_internal_networks.return_value = {}

        self.mock_ansible_module.params = PARAMS_INTERNAL_NETWORKS

        LogicalInterconnectModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(
            exception=mock.ANY, msg=LogicalInterconnectModule.MSG_ETH_NETWORK_NOT_FOUND + "Network Name 2")
    def test_should_do_nothing_when_no_changes_port_flap_settings(self):
        self.resource.data = LOGICAL_INTERCONNECT
        self.resource.update_port_flap_settings.return_value = self.port_flap_config

        self.mock_ansible_module.params = PARAMS_PORT_FLAP_SETTINGS_NO_CHANGES

        LogicalInterconnectModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=LogicalInterconnectModule.MSG_NO_CHANGES_PROVIDED)
    def test_should_update_port_flap_settings(self):
        self.resource.data = LOGICAL_INTERCONNECT
        self.resource.update_port_flap_settings.return_value = self.port_flap_config

        self.mock_ansible_module.params = PARAMS_PORT_FLAP_SETTINGS

        LogicalInterconnectModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=LogicalInterconnectModule.MSG_PORT_FLAP_SETTINGS_UPDATED,
            ansible_facts=dict(port_flap_settings=self.port_flap_config))
    def test_should_update_configuration(self):
        self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
        self.resource.update_configuration.return_value = LOGICAL_INTERCONNECT

        self.mock_ansible_module.params = PARAMS_CONFIGURATION

        LogicalInterconnectModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=LogicalInterconnectModule.MSG_CONFIGURATION_UPDATED,
            ansible_facts=dict(logical_interconnect=LOGICAL_INTERCONNECT))
Exemplo n.º 12
0
    def test_should_update_internal_networks_with_given_list(self):
        self.resource.data = LOGICAL_INTERCONNECT
        self.mock_ov_client.ethernet_networks.get_by.side_effect = [[{'uri': '/path/1'}], [{'uri': '/path/2'}]]
        self.resource.update_internal_networks.return_value = LOGICAL_INTERCONNECT

        self.mock_ansible_module.params = PARAMS_INTERNAL_NETWORKS

        LogicalInterconnectModule().run()

        expected_list = ['/path/1', '/path/2', '/path/3']
        self.resource.update_internal_networks.assert_called_once_with(
            expected_list)
    def test_should_install_firmware(self):
        self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
        self.resource.install_firmware.return_value = self.response

        self.mock_ansible_module.params = PARAMS_FIRMWARE_WITH_SPP_NAME

        LogicalInterconnectModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=LogicalInterconnectModule.MSG_FIRMWARE_INSTALLED,
            ansible_facts=dict(li_firmware=self.response))
    def test_should_generate_interconnect_fib(self):
        self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
        self.resource.create_forwarding_information_base.return_value = self.response_body

        self.mock_ansible_module.params = PARAMS_GENERATE_FIB

        LogicalInterconnectModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=self.status,
            ansible_facts=dict(interconnect_fib=self.response_body))
    def test_should_do_nothing_when_no_changes_port_monitor(self):
        self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
        self.resource.get_port_monitor.return_value = self.monitor_config
        self.resource.update_port_monitor.return_value = self.monitor_config

        self.mock_ansible_module.params = PARAMS_PORT_MONITOR_CONFIGURATION_NO_CHANGES

        LogicalInterconnectModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=LogicalInterconnectModule.MSG_NO_CHANGES_PROVIDED)
    def test_should_do_nothing_when_no_changes_snmp(self):
        self.resource.data = LOGICAL_INTERCONNECT
        self.resource.get_snmp_configuration.return_value = self.snmp_config
        self.resource.update_snmp_configuration.return_value = self.snmp_config

        self.mock_ansible_module.params = PARAMS_SNMP_CONFIG_NO_CHANGES

        LogicalInterconnectModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=LogicalInterconnectModule.MSG_NO_CHANGES_PROVIDED)
    def test_should_update_ethernet_settings(self):
        self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
        self.resource.update_ethernet_settings.return_value = LOGICAL_INTERCONNECT

        self.mock_ansible_module.params = PARAMS_ETHERNET_SETTINGS

        LogicalInterconnectModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=LogicalInterconnectModule.MSG_ETH_SETTINGS_UPDATED,
            ansible_facts=dict(logical_interconnect=LOGICAL_INTERCONNECT))
    def test_should_return_to_a_consistent_state(self):
        self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
        self.resource.update_compliance.return_value = LOGICAL_INTERCONNECT

        self.mock_ansible_module.params = PARAMS_COMPLIANCE

        LogicalInterconnectModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=LogicalInterconnectModule.MSG_CONSISTENT,
            ansible_facts=dict(logical_interconnect=LOGICAL_INTERCONNECT))
    def test_should_update_snmp_configuration(self):
        self.resource.data = LOGICAL_INTERCONNECT
        self.resource.get_snmp_configuration.return_value = self.snmp_config
        self.resource.update_snmp_configuration.return_value = self.snmp_config

        self.mock_ansible_module.params = PARAMS_SNMP_CONFIG

        LogicalInterconnectModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=LogicalInterconnectModule.MSG_SNMP_UPDATED,
            ansible_facts=dict(snmp_configuration=self.snmp_config))
    def test_should_update_qos_aggreg_config(self):
        self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
        self.resource.get_qos_aggregated_configuration.return_value = self.qos_config
        self.resource.update_qos_aggregated_configuration.return_value = self.qos_config

        self.mock_ansible_module.params = PARAMS_QOS_AGGREG_CONFIG

        LogicalInterconnectModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=LogicalInterconnectModule.MSG_QOS_UPDATED,
            ansible_facts=dict(qos_configuration=self.qos_config))
    def test_should_update_port_monitor_configuration(self):
        self.resource.data = LOGICAL_INTERCONNECT
        self.resource.get_port_monitor.return_value = self.monitor_config
        self.resource.update_port_monitor.return_value = self.monitor_config

        self.mock_ansible_module.params = PARAMS_PORT_MONITOR_CONFIGURATION

        LogicalInterconnectModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=LogicalInterconnectModule.MSG_PORT_MONITOR_UPDATED,
            ansible_facts=dict(port_monitor=self.monitor_config))
    def test_should_update_bulk_inconsistency(self):
        self.resource.data = LOGICAL_INTERCONNECT
        self.resource.bulk_inconsistency_validate.return_value = self.li_inconsistency_data

        self.mock_ansible_module.params = PARAMS_BULK_INCONSISTENCY

        LogicalInterconnectModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=LogicalInterconnectModule.MSG_INCONSISTENCY_VALIDATED,
            ansible_facts=dict(
                li_inconsistency_report=self.li_inconsistency_data))
Exemplo n.º 23
0
    def test_should_update_internal_networks(self):
        self.resource.data = LOGICAL_INTERCONNECT
        self.mock_ov_client.ethernet_networks.get_by.side_effect = [[{'uri': '/path/1'}], [{'uri': '/path/2'}]]
        self.resource.update_internal_networks.return_value = LOGICAL_INTERCONNECT

        self.mock_ansible_module.params = PARAMS_INTERNAL_NETWORKS

        LogicalInterconnectModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=LogicalInterconnectModule.MSG_INTERNAL_NETWORKS_UPDATED,
            ansible_facts=dict(logical_interconnect=LOGICAL_INTERCONNECT)
        )
    def test_update_telemetry_configuration(self):
        self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
        self.resource.update_telemetry_configurations.return_value = LOGICAL_INTERCONNECT

        telemetry_config = LOGICAL_INTERCONNECT['telemetryConfiguration']

        self.mock_ansible_module.params = TELEMETRY_PARAMS_CONFIGURATION

        LogicalInterconnectModule().run()

        self.resource.update_telemetry_configurations.assert_called_once_with(
            self.telemetry_config_uri, TELEMETRY_CONFIG)
        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=LogicalInterconnectModule.MSG_TELEMETRY_CONFIGURATION_UPDATED,
            ansible_facts=dict(telemetry_configuration=telemetry_config))
    def test_should_do_nothing_when_scopes_are_the_same(self):
        params_to_scope = PARAMS_SCOPES.copy()
        params_to_scope['data']['scopeUris'] = ['test']
        self.mock_ansible_module.params = params_to_scope

        resource_data = LOGICAL_INTERCONNECT.copy()
        resource_data['scopeUris'] = ['test']
        self.resource.get_by_name.return_value = resource_data

        LogicalInterconnectModule().run()

        self.resource.patch.not_been_called()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(scope_uris=['test']),
            msg=LogicalInterconnectModule.MSG_NO_CHANGES_PROVIDED)
    def test_update_settings_should_do_nothing_when_data_was_not_modified(
            self):
        self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
        self.resource.update_settings.return_value = LOGICAL_INTERCONNECT

        params = PARAMS_SETTINGS.copy()
        params['data']['ethernetSettings']['macRefreshInterval'] = 10
        params['data']['fcoeSettings']['fcoeMode'] = 'Unknown'

        self.mock_ansible_module.params = PARAMS_SETTINGS

        LogicalInterconnectModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=LogicalInterconnectModule.MSG_NO_CHANGES_PROVIDED,
            ansible_facts=dict(logical_interconnect=LOGICAL_INTERCONNECT))
Exemplo n.º 27
0
    def test_should_update_fcoe_settings(self):
        self.resource.data = LOGICAL_INTERCONNECT
        self.resource.update_settings.return_value = LOGICAL_INTERCONNECT

        self.mock_ansible_module.params = PARAMS_SETTTINGS_FCOE

        LogicalInterconnectModule().run()

        expected_settings = {
            'ethernetSettings': {
                'enableIgmpSnooping': True,
                'macRefreshInterval': 10
            },
            'fcoeSettings': {
                'fcoeMode': 'NotApplicable'
            }
        }
        self.resource.update_settings.assert_called_once_with(expected_settings)
    def test_should_update_settings_ethernet(self):
        self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
        self.resource.update_settings.return_value = LOGICAL_INTERCONNECT

        self.mock_ansible_module.params = PARAMS_SETTINGS_ETHERNET

        LogicalInterconnectModule().run()

        expected_uri = '/rest/logical-interconnects/id'
        expected_settings = {
            'ethernetSettings': {
                'enableIgmpSnooping': True,
                'macRefreshInterval': 12
            },
            'fcoeSettings': {
                'fcoeMode': 'Unknown'
            }
        }
        self.resource.update_settings.assert_called_once_with(
            expected_uri, expected_settings)
    def test_update_scopes_when_different(self):
        self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT

        params_to_scope = PARAMS_SCOPES.copy()
        params_to_scope['data']['scopeUris'] = ['test']
        self.mock_ansible_module.params = params_to_scope

        patch_return = LOGICAL_INTERCONNECT.copy()
        patch_return['scopeUris'] = ['test']
        self.resource.patch.return_value = patch_return

        LogicalInterconnectModule().run()

        self.resource.patch.assert_called_once_with(
            '/rest/logical-interconnects/id',
            operation='replace',
            path='/scopeUris',
            value=['test'])

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            ansible_facts=dict(scope_uris=['test']),
            msg=LogicalInterconnectModule.MSG_SCOPES_UPDATED)