Beispiel #1
0
    def test_should_fail_when_no_key_is_provided(self):
        params = PARAMS_FOR_RESET_DEVICE_BY_IP.copy()
        params['ip'] = None

        self.mock_ansible_module.params = params

        InterconnectModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(
            exception=mock.ANY, msg=InterconnectModule.MSG_MISSING_KEY)
Beispiel #2
0
    def test_should_fail_when_interconnect_was_not_found(self):
        ansible_arguments = create_params_for('device_reset')
        self.mock_ansible_module.params = ansible_arguments

        self.resource.get_by_uri.return_value = []
        self.resource.get_by_name.return_value = []

        InterconnectModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(
            exception=mock.ANY,
            msg=InterconnectModule.MSG_INTERCONNECT_NOT_FOUND)
Beispiel #3
0
    def test_should_return_changed_false_when_uid_is_already_off(self):
        ansible_arguments = create_params_for('uid_off')
        self.mock_ansible_module.params = ansible_arguments

        self.resource.data = dict(uidState='Off')
        self.resource.get_by_uri.return_value = self.resource

        InterconnectModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=InterconnectModule.MSG_UID_STATE_ALREADY_OFF,
            ansible_facts=dict(interconnect=self.resource.data))
Beispiel #4
0
    def test_should_return_changed_false_when_interconnect_is_already_powered_off(
            self):
        ansible_arguments = create_params_for('powered_off')
        self.mock_ansible_module.params = ansible_arguments

        FAKE_INTERCONNECT = dict(powerState='Off')
        self.resource.data = FAKE_INTERCONNECT
        self.resource.get_by_uri.return_value = self.resource

        InterconnectModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=InterconnectModule.MSG_ALREADY_POWERED_OFF,
            ansible_facts=dict(interconnect=FAKE_INTERCONNECT))
Beispiel #5
0
    def test_should_ensure_device_reset_by_ip_address(self):
        self.mock_ansible_module.params = PARAMS_FOR_RESET_DEVICE_BY_IP

        self.resource.data = FAKE_INTERCONNECT
        self.resource.get_by_uri.return_value = self.resource

        self.resource.patch.return_value = self.resource

        InterconnectModule().run()

        self.resource.get_by.assert_called_with('interconnectIP',
                                                INTERCONNECT_IP)

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=InterconnectModule.MSG_RESET,
            ansible_facts=dict(interconnect=FAKE_INTERCONNECT))
Beispiel #6
0
    def test_should_update_configuration(self):
        self.mock_ansible_module.params = PARAMS_FOR_UPDATE_CONFIGURATION

        self.resource.data = FAKE_INTERCONNECT
        self.resource.get_by_uri.return_value = self.resource

        self.resource.update_configuration.return_value = FAKE_INTERCONNECT

        InterconnectModule().run()

        self.resource.get_by.assert_called_with("interconnectIP",
                                                INTERCONNECT_IP)
        self.resource.update_configuration.assert_called()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=InterconnectModule.MSG_RECONFIGURED,
            ansible_facts=dict(interconnect=FAKE_INTERCONNECT))
Beispiel #7
0
    def test_should_reset_port_protection(self):
        self.mock_ansible_module.params = PARAMS_FOR_RESET_PORT_PROTECTION

        self.resource.data = FAKE_INTERCONNECT
        self.resource.get_by_uri.return_value = self.resource

        self.resource.reset_port_protection.return_value = FAKE_INTERCONNECT

        InterconnectModule().run()

        self.resource.get_by.assert_called_with('interconnectIP',
                                                INTERCONNECT_IP)
        self.resource.reset_port_protection.assert_called()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=InterconnectModule.MSG_RESET_PORT_PROTECTION,
            ansible_facts=dict(interconnect=FAKE_INTERCONNECT))
Beispiel #8
0
    def test_should_not_update_when_ports_not_provided(self):
        self.mock_ansible_module.params = deepcopy(PARAMS_FOR_UPDATE_PORTS)
        self.mock_ansible_module.params['ports'] = []

        self.resource.data = FAKE_INTERCONNECT
        self.resource.get_by_uri.return_value = self.resource

        self.resource.update_ports.return_value = FAKE_INTERCONNECT

        InterconnectModule().run()

        self.resource.get_by.assert_called_with('interconnectIP',
                                                INTERCONNECT_IP)

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=InterconnectModule.MSG_PORTS_ALREADY_UPDATED,
            ansible_facts=dict(interconnect=FAKE_INTERCONNECT))
Beispiel #9
0
    def test_should_update_the_interconnect_ports(self):
        self.mock_ansible_module.params = PARAMS_FOR_UPDATE_PORTS

        self.resource.data = FAKE_INTERCONNECT
        self.resource.get_by_uri.return_value = self.resource

        self.resource.update_ports.return_value = FAKE_INTERCONNECT

        InterconnectModule().run()

        self.resource.get_by.assert_called_with('interconnectIP',
                                                INTERCONNECT_IP)
        self.resource.update_ports.assert_called_with(ports=PORTS_FOR_UPDATE)

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=InterconnectModule.MSG_PORTS_UPDATED,
            ansible_facts=dict(interconnect=FAKE_INTERCONNECT))
Beispiel #10
0
    def test_should_ensure_device_reset(self):
        ansible_arguments = create_params_for('device_reset')
        self.mock_ansible_module.params = ansible_arguments

        self.resource.data = FAKE_INTERCONNECT
        self.resource.get_by_uri.return_value = self.resource

        self.resource.patch.return_value = self.resource

        InterconnectModule().run()

        self.resource.patch.assert_called_with(operation='replace',
                                               path='/deviceResetState',
                                               value='Reset')
        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=InterconnectModule.MSG_RESET,
            ansible_facts=dict(interconnect=FAKE_INTERCONNECT))
Beispiel #11
0
    def test_should_ensure_powered_on_state(self):
        ansible_arguments = create_params_for('powered_on')
        self.mock_ansible_module.params = ansible_arguments

        self.resource.data = dict(powerState='Off', uri=FAKE_URI)
        self.resource.get_by_uri.return_value = self.resource

        FAKE_INTERCONNECT_updated = dict(powerState='On')
        obj = self.resource.copy()
        obj.data = FAKE_INTERCONNECT_updated
        self.resource.patch.return_value = obj

        InterconnectModule().run()

        self.resource.patch.assert_called_with(operation='replace',
                                               path='/powerState',
                                               value='On')
        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=InterconnectModule.MSG_POWERED_ON,
            ansible_facts=dict(interconnect=FAKE_INTERCONNECT_updated))