Example #1
0
    def test_create_host_fail(self):
        """Verify create_host produces expected exceptions."""
        def _assigned_host_ports(apply_unassigning=False):
            return None

        with self.assertRaisesRegexp(AnsibleFailJson, "Failed to create host."):
            with mock.patch(self.REQ_FUNC, return_value=Exception()):
                self._set_args({'state': 'present', 'name': 'beegfs_metadata1', 'host_type': 'windows', 'force_port': True, 'group': 'test_group',
                                'ports': [{'label': 'beegfs_metadata1_iscsi_1', 'type': 'iscsi',
                                           'port': 'iqn.1993-08.org.debian.beegfs-storage1:01:b0621126818'}]})
                host = Host()
                host.host_exists = lambda: False
                host.assigned_host_ports = _assigned_host_ports
                host.build_success_payload = lambda x: {}
                host.group_id = lambda: "85000000600A098000A4B9D1003637135D483DEB"
                host.create_host()

        with self.assertRaisesRegexp(AnsibleExitJson, "Host already exists."):
            self._set_args({'state': 'present', 'name': 'beegfs_metadata1', 'host_type': 'windows', 'force_port': True, 'group': 'test_group',
                            'ports': [{'label': 'beegfs_metadata1_iscsi_1', 'type': 'iscsi',
                                       'port': 'iqn.1993-08.org.debian.beegfs-storage1:01:b0621126818'}]})
            host = Host()
            host.host_exists = lambda: True
            host.assigned_host_ports = _assigned_host_ports
            host.build_success_payload = lambda x: {}
            host.group_id = lambda: "85000000600A098000A4B9D1003637135D483DEB"
            host.create_host()
Example #2
0
    def test_assigned_host_ports_pass(self):
        """Verify assigned_host_ports gives expected results."""

        # Add an unused port to host
        with mock.patch(self.REQ_FUNC, return_value=(200, self.EXISTING_HOSTS)):
            self._set_args({'state': 'present', 'name': 'beegfs_metadata1', 'host_type': 'linux dm-mp', 'force_port': False,
                            'ports': [{'label': 'beegfs_metadata1_iscsi_1', 'type': 'iscsi', 'port': 'iqn.not_used'}]})
            host = Host()
            host.host_exists()
            self.assertTrue(host.needs_update())
            self.assertEqual(host.assigned_host_ports(), {})

        # Change port name (force)
        with mock.patch(self.REQ_FUNC, return_value=(200, self.EXISTING_HOSTS)):
            self._set_args({'state': 'present', 'name': 'beegfs_metadata1', 'host_type': 'linux dm-mp', 'force_port': True,
                            'ports': [{'label': 'beegfs_metadata1_iscsi_2', 'type': 'iscsi',
                                       'port': 'iqn.1993-08.org.debian.beegfs-metadata:01:69e4efdf30b8'}]})
            host = Host()
            host.host_exists()
            self.assertTrue(host.needs_update())
            self.assertEqual(host.assigned_host_ports(), {'84000000600A098000A4B9D10030370B5D430109': ['89000000600A098000A4B28D00303CFC5D4300F7']})

        # Change port type
        with mock.patch(self.REQ_FUNC, return_value=(200, self.EXISTING_HOSTS)):
            self._set_args({'state': 'present', 'name': 'beegfs_metadata1', 'host_type': 'linux dm-mp', 'force_port': True,
                            'ports': [{'label': 'beegfs_metadata1_iscsi_1', 'type': 'fc', 'port': '08:ef:7e:24:52:a0'}]})
            host = Host()
            host.host_exists()
            self.assertTrue(host.needs_update())
            self.assertEqual(host.assigned_host_ports(), {})

        # take port from another host by force
        with mock.patch(self.REQ_FUNC, return_value=(200, self.EXISTING_HOSTS)):
            self._set_args({'state': 'present', 'name': 'beegfs_metadata1', 'host_type': 'linux dm-mp', 'force_port': True,
                            'ports': [{'label': 'beegfs_metadata2_iscsi_0', 'type': 'iscsi', 'port': 'iqn.used_elsewhere'}]})
            host = Host()
            host.host_exists()
            self.assertTrue(host.needs_update())
            self.assertEqual(host.assigned_host_ports(), {'84000000600A098000A4B9D10030370B5D430109': ['89000000600A098000A4B28D00303CFC5D4300F7']})

        # take port from another host by force
        with mock.patch(self.REQ_FUNC, side_effect=[(200, self.EXISTING_HOSTS), (200, {})]):
            self._set_args({'state': 'present', 'name': 'beegfs_metadata1', 'host_type': 'linux dm-mp', 'force_port': True,
                            'ports': [{'label': 'beegfs_metadata2_iscsi_0', 'type': 'iscsi', 'port': 'iqn.used_elsewhere'}]})
            host = Host()
            host.host_exists()
            self.assertTrue(host.needs_update())
            self.assertEqual(host.assigned_host_ports(apply_unassigning=True),
                             {'84000000600A098000A4B9D10030370B5D430109': ['89000000600A098000A4B28D00303CFC5D4300F7']})
Example #3
0
    def test_assigned_host_ports_fail(self):
        """Verify assigned_host_ports gives expected exceptions."""
        # take port from another
        with self.assertRaisesRegexp(AnsibleFailJson, "There are no host ports available OR there are not enough unassigned host ports"):
            with mock.patch(self.REQ_FUNC, side_effect=[(200, self.EXISTING_HOSTS)]):
                self._set_args({'state': 'present', 'name': 'beegfs_metadata1', 'host_type': 'linux dm-mp', 'force_port': False,
                                'ports': [{'label': 'beegfs_metadata1_iscsi_2', 'type': 'iscsi',
                                           'port': 'iqn.1993-08.org.debian.beegfs-metadata:01:69e4efdf30b8'}]})
                host = Host()
                host.host_exists()
                self.assertTrue(host.needs_update())
                host.assigned_host_ports(apply_unassigning=True)

        # take port from another host and fail because force == False
        with self.assertRaisesRegexp(AnsibleFailJson, "There are no host ports available OR there are not enough unassigned host ports"):
            with mock.patch(self.REQ_FUNC, side_effect=[(200, self.EXISTING_HOSTS)]):
                self._set_args({'state': 'present', 'name': 'beegfs_metadata1', 'host_type': 'linux dm-mp', 'force_port': False,
                                'ports': [{'label': 'beegfs_metadata2_iscsi_0', 'type': 'iscsi', 'port': 'iqn.used_elsewhere'}]})
                host = Host()
                host.host_exists()
                self.assertTrue(host.needs_update())
                host.assigned_host_ports(apply_unassigning=True)

        # take port from another host and fail because force == False
        with self.assertRaisesRegexp(AnsibleFailJson, "There are no host ports available OR there are not enough unassigned host ports"):
            with mock.patch(self.REQ_FUNC, side_effect=[(200, self.EXISTING_HOSTS)]):
                self._set_args({'state': 'present', 'name': 'beegfs_metadata3', 'host_type': 'linux dm-mp', 'force_port': False,
                                'ports': [{'label': 'beegfs_metadata2_iscsi_0', 'type': 'iscsi', 'port': 'iqn.used_elsewhere'}]})
                host = Host()
                host.host_exists()
                host.assigned_host_ports(apply_unassigning=True)

        with self.assertRaisesRegexp(AnsibleFailJson, "Failed to unassign host port."):
            with mock.patch(self.REQ_FUNC, side_effect=[(200, self.EXISTING_HOSTS), Exception()]):
                self._set_args({'state': 'present', 'name': 'beegfs_metadata1', 'host_type': 'linux dm-mp', 'force_port': True,
                                'ports': [{'label': 'beegfs_metadata2_iscsi_0', 'type': 'iscsi', 'port': 'iqn.used_elsewhere'}]})
                host = Host()
                host.host_exists()
                self.assertTrue(host.needs_update())
                host.assigned_host_ports(apply_unassigning=True)