Ejemplo n.º 1
0
 def test_power_off_not_installed(self, zboot, rack):
     instance = ZerobootRacktivityHost(name="test", data=self._valid_data)
     with pytest.raises(
             StateCheckError,
             message=
             "power_off should be not be able to be called before install"):
         instance.power_off()
Ejemplo n.º 2
0
 def test_monitor_not_installed(self):
     instance = ZerobootRacktivityHost(name="test", data=self._valid_data)
     with pytest.raises(
             StateCheckError,
             message=
             "monitor should be not be able to be called before install"):
         instance.monitor()
Ejemplo n.º 3
0
    def test_configure_ipxe_boot_not_installed(self, zboot):
        boot_url = "some.url"
        instance = ZerobootRacktivityHost(name="test", data=self._valid_data)

        with pytest.raises(
                StateCheckError,
                message=
                "monitor should be not be able to be called before install"):
            instance.configure_ipxe_boot(boot_url)
Ejemplo n.º 4
0
    def test_power_status(self, zboot, rack):
        instance = ZerobootRacktivityHost(name="test", data=self._valid_data)
        instance.state.set('actions', 'install', 'ok')
        rack.get = MagicMock()

        instance.power_status()

        expected_calls = []
        for d in reversed(self._valid_data['racktivities']):
            expected_calls.append(zboot.get().port_info(
                d['port'], mock.ANY, d['powermodule']))
Ejemplo n.º 5
0
    def test_uninstall(self, zboot):
        instance = ZerobootRacktivityHost(name="test", data=self._valid_data)
        instance.state.set('actions', 'install', 'ok')

        instance.uninstall()

        instance._network.hosts.remove.assert_called_with(
            self._valid_data['hostname'])

        with pytest.raises(StateCheckError,
                           message="install action state check should fail"):
            instance.state.check('actions', 'install', 'ok')
Ejemplo n.º 6
0
    def test_install(self, zboot, rack):
        instance = ZerobootRacktivityHost(name="test", data=self._valid_data)
        instance._network.hosts.list = MagicMock(return_value=[])

        instance.install()

        instance._network.hosts.add.assert_called_with(
            self._valid_data['mac'], self._valid_data['ip'],
            self._valid_data['hostname'])
        instance._host.configure_ipxe_boot.assert_called_with(
            self._valid_data['lkrnUrl'])

        # state check should pass
        instance.state.check('actions', 'install', 'ok')
Ejemplo n.º 7
0
    def test_validate_no_zboot_instance(self, zboot, rack):
        instance = ZerobootRacktivityHost(name="test", data=self._valid_data)

        zboot.list = MagicMock(return_value=[])
        rack.list = MagicMock(return_value=self._rack_clients)
        instance.power_status = MagicMock(return_value=True)

        with pytest.raises(
                LookupError,
                message="zeroboot instance should not be present") as excinfo:
            instance.validate()
        if "zboot client" not in str(excinfo.value):
            pytest.fail(
                "Received unexpected error message for missing zboot instance: %s"
                % str(excinfo.value))
Ejemplo n.º 8
0
    def test_invalid_racktivity_port(self, zboot, rack):
        zboot.list = MagicMock(
            return_value=[self._valid_data['zerobootClient']])
        rack.list = MagicMock(return_value=self._rack_clients)

        data = {
            'zerobootClient': 'zboot1-zb',
            'racktivities': [
                {
                    'client': 'zboot1-rack',
                    'powermodule': 'P1',
                },
            ],
            'mac': 'well:this:a:weird:mac:address',
            'ip': '10.10.1.1',
            'network': '10.10.1.0/24',
            'hostname': 'test-01',
            'lkrnUrl': 'some.ixpe.url',
        }
        instance = ZerobootRacktivityHost(name="test", data=data)

        with pytest.raises(
                ValueError,
                message="Should fail due to missing racktivity port"):
            instance.validate()

        data = {
            'zerobootClient':
            'zboot1-zb',
            'racktivities': [
                {
                    'client': 'zboot1-rack',
                    'port': 'FOO',
                    'powermodule': 'P1',
                },
            ],
            'mac':
            'well:this:a:weird:mac:address',
            'ip':
            '10.10.1.1',
            'network':
            '10.10.1.0/24',
            'hostname':
            'test-01',
            'lkrnUrl':
            'some.ixpe.url',
        }
        instance = ZerobootRacktivityHost(name="test", data=data)

        with pytest.raises(
                ValueError,
                message="Should fail due to invalid racktivity port"):
            instance.validate()
Ejemplo n.º 9
0
    def test_monitor_power_off(self):
        instance = ZerobootRacktivityHost(name="test", data=self._valid_data)
        instance.state.set('actions', 'install', 'ok')
        instance.power_on = MagicMock()
        instance.power_off = MagicMock()
        instance.power_status = MagicMock(return_value=True)
        instance.data['powerState'] = False

        instance.monitor()

        # power state mismatched, power_off should have been called
        instance.power_on.assert_not_called()
        instance.power_off.assert_called_with()
Ejemplo n.º 10
0
    def test_monitor_matching_state(self):
        instance = ZerobootRacktivityHost(name="test", data=self._valid_data)
        instance.state.set('actions', 'install', 'ok')
        instance.power_on = MagicMock()
        instance.power_off = MagicMock()
        instance.power_status = MagicMock(return_value=True)
        instance.data['powerState'] = True

        instance.monitor()

        # no power calls should be make
        instance.power_on.assert_not_called()
        instance.power_off.assert_not_called()
Ejemplo n.º 11
0
    def test_configure_ipxe_boot(self, zboot):
        boot_url = "some.url"
        instance = ZerobootRacktivityHost(name="test", data=self._valid_data)
        instance.state.set('actions', 'install', 'ok')

        # call with same ipxe URL as set in data
        instance.configure_ipxe_boot(self._valid_data["lkrnUrl"])
        instance._host.configure_ipxe_boot.assert_not_called()

        # call with difference ipxe URL as set in data
        instance.configure_ipxe_boot(boot_url)
        instance._host.configure_ipxe_boot.assert_called_with(boot_url)

        assert instance.data["lkrnUrl"] == boot_url
Ejemplo n.º 12
0
    def test_validation_required_fields(self, zboot, rack):
        zboot.list = MagicMock(
            return_value=[self._valid_data['zerobootClient']])
        rack.list = MagicMock(return_value=self._rack_clients)

        test_cases = [
            {
                'data': {
                    'racktivities': [
                        {
                            'client': 'zboot1-rack',
                            'port': 6,
                            'powermodule': 'P1',
                        },
                        {
                            'client': 'zboot1-rack',
                            'port': 7,
                            'powermodule': 'P1',
                        },
                    ],
                    'mac':
                    'well:this:a:weird:mac:address',
                    'ip':
                    '10.10.1.1',
                    'network':
                    '10.10.1.0/24',
                    'hostname':
                    'test-01',
                    'lkrnUrl':
                    'some.ixpe.url',
                },
                'message': "Should fail: missing zerobootClient",
                'missing': 'zerobootClient',
            },
            {
                'data': {
                    'zerobootClient': 'zboot1-zb',
                    'mac': 'well:this:a:weird:mac:address',
                    'ip': '10.10.1.1',
                    'network': '10.10.1.0/24',
                    'hostname': 'test-01',
                    'lkrnUrl': 'some.ixpe.url',
                },
                'message': "Should fail: missing racktivities",
                'missing': 'racktivities',
            },
            {
                'data': {
                    'zerobootClient':
                    'zboot1-zb',
                    'racktivities': [
                        {
                            'client': 'zboot1-rack',
                            'port': 6,
                            'powermodule': 'P1',
                        },
                        {
                            'client': 'zboot1-rack',
                            'port': 7,
                            'powermodule': 'P1',
                        },
                    ],
                    'mac':
                    'well:this:a:weird:mac:address',
                    'ip':
                    '10.10.1.1',
                    'hostname':
                    'test-01',
                    'lkrnUrl':
                    'some.ixpe.url',
                },
                'message': "Should fail: missing network",
                'missing': 'network',
            },
            {
                'data': {
                    'zerobootClient':
                    'zboot1-zb',
                    'racktivities': [
                        {
                            'client': 'zboot1-rack',
                            'port': 6,
                            'powermodule': 'P1',
                        },
                        {
                            'client': 'zboot1-rack',
                            'port': 7,
                            'powermodule': 'P1',
                        },
                    ],
                    'mac':
                    'well:this:a:weird:mac:address',
                    'ip':
                    '10.10.1.1',
                    'network':
                    '10.10.1.0/24',
                    'lkrnUrl':
                    'some.ixpe.url',
                },
                'message': "Should fail: missing hostname",
                'missing': 'hostname',
            },
            {
                'data': {
                    'zerobootClient':
                    'zboot1-zb',
                    'racktivities': [
                        {
                            'client': 'zboot1-rack',
                            'port': 6,
                            'powermodule': 'P1',
                        },
                        {
                            'client': 'zboot1-rack',
                            'port': 7,
                            'powermodule': 'P1',
                        },
                    ],
                    'ip':
                    '10.10.1.1',
                    'network':
                    '10.10.1.0/24',
                    'hostname':
                    'test-01',
                    'lkrnUrl':
                    'some.ixpe.url',
                },
                'message': "Should fail: missing mac address",
                'missing': 'mac',
            },
            {
                'data': {
                    'zerobootClient':
                    'zboot1-zb',
                    'racktivities': [
                        {
                            'client': 'zboot1-rack',
                            'port': 6,
                            'powermodule': 'P1',
                        },
                        {
                            'client': 'zboot1-rack',
                            'port': 7,
                            'powermodule': 'P1',
                        },
                    ],
                    'network':
                    '10.10.1.0/24',
                    'mac':
                    'well:this:a:weird:mac:address',
                    'hostname':
                    'test-01',
                },
                'message': "Should fail: missing ip address",
                'missing': 'ip',
            },
        ]

        for tc in test_cases:
            instance = ZerobootRacktivityHost(name="test", data=tc['data'])

            with pytest.raises(ValueError,
                               message="Unexpected success: %s\n\nData: %s" %
                               (tc['message'], tc['data'])) as excinfo:
                instance.validate()

            if tc['missing'] not in str(excinfo):
                pytest.fail(
                    "Error message did not contain missing field('%s'): %s" %
                    (tc['missing'], str(excinfo)))
Ejemplo n.º 13
0
    def test_validation_valid_data(self, zboot, rack):
        zboot.list = MagicMock(
            return_value=[self._valid_data['zerobootClient']])
        rack.list = MagicMock(return_value=self._rack_clients)

        _ = ZerobootRacktivityHost(name="test", data=self._valid_data)