Example #1
0
    def test_resolve_devices_duplicate_device_basenames(self):
        """
        Check when zpool contains duplicate device basenames the listed partitions are resolved to the correct devices
        """
        self.add_commands(
            CommandCaptureCommand(
                ("zpool", "list", "-PHv", "-o", "name", "zfsPool1"),
                stdout="""\
zfsPool1
        /dev/sde1   9.94G   228K    9.94G   -       0%      0%
        /dev/disk/by-id/scsi-SCSI_DISK_1a/scsi-SCSI_DISK_1-part1   9.94G   228K    9.94G   -       0%      0%
        /dev/disk/by-id/scsi-SCSI_DISK_1b/scsi-SCSI_DISK_1-part1   9.94G   228K    9.94G   -       0%      0%\n"""
            ),
            CommandCaptureCommand(
                ("zpool", "list", "-Hv", "-o", "name", "zfsPool1"),
                stdout="""\
zfsPool1
        sde   9.94G   228K    9.94G   -       0%      0%
        scsi-SCSI_DISK_1   9.94G   228K    9.94G   -       0%      0%
        scsi-SCSI_DISK_1   9.94G   228K    9.94G   -       0%      0%\n"""))

        self.assertItemsEqual(self._get_zfs_devices('zfsPool1'), [
            '/dev/disk/by-id/scsi-SCSI_DISK_1a/scsi-SCSI_DISK_1',
            '/dev/disk/by-id/scsi-SCSI_DISK_1b/scsi-SCSI_DISK_1', '/dev/sde'
        ])
        self.assertRanAllCommandsInOrder()
    def test_import_existing_readonly(self):
        props = re.sub(r"readonly\s+off", "readonly    on",
                       example_data.zpool_example_properties)

        self.add_commands(
            CommandCaptureCommand(
                ("zpool", "import", self.pool_name),
                rc=1,
                stderr=
                "cannot import '%s': a pool with that name already exists\n"
                "use the form 'zpool import <pool | id> <newpool>' to give it "
                "a new name\n",
                executions_remaining=1,
            ),
            CommandCaptureCommand(
                ("zpool", "get", "-Hp", "all", self.pool_name),
                stdout=props,
                executions_remaining=1),
            CommandCaptureCommand(("zpool", "export", self.pool_name)),
            CommandCaptureCommand(("zpool", "import", self.pool_name),
                                  executions_remaining=1),
            CommandCaptureCommand(
                ("zpool", "get", "-Hp", "all", self.pool_name),
                stdout=example_data.zpool_example_properties),
        )

        self.blockdevice = BlockDeviceZfs("zfs", self.dataset_path)

        self.assertIsNone(self.blockdevice.import_(False))
        self.assertRanAllCommandsInOrder()
Example #3
0
    def test_install_packages_hyd_4050_grubby(self):
        self.add_commands(
            CommandCaptureCommand(('dnf', 'clean', 'all', '--enablerepo=*')),
            CommandCaptureCommand(('dnf', 'repoquery', '--latest-limit', '1',
                                   '--requires', '--enablerepo=myrepo', 'foo'),
                                  stdout="""/usr/bin/python
python >= 2.4
python(abi) = 2.6
yum >= 3.2.29
/bin/sh
kernel = 2.6.32-279.14.1.el6_lustre
lustre-backend-fs
        """),
            CommandCaptureCommand(
                ('dnf', 'install', '--allowerasing', '-y', '--exclude',
                 'kernel-debug', '--enablerepo=myrepo', 'foo',
                 'kernel-2.6.32-279.14.1.el6_lustre')),
            CommandCaptureCommand((
                'dnf', 'repoquery',
                '--queryformat=%{name} %{version}-%{release}.%{arch} %{repoid}',
                '--upgrades', '--disablerepo=*', '--enablerepo=myrepo')),
            CommandCaptureCommand(('grubby', '--default-kernel'), rc=1))

        def isfile(arg):
            return True

        with patch('os.path.isfile', side_effect=isfile):
            self.assertTrue(
                'error' in agent_updates.install_packages(['myrepo'], ['foo']))

        self.assertRanAllCommandsInOrder()
    def test_install_packages_hyd_4050_grubby(self):
        self.add_commands(
            CommandCaptureCommand(("yum", "clean", "all", "--enablerepo=*")),
            CommandCaptureCommand(
                ("repoquery", "--requires", "--enablerepo=myrepo", "foo"),
                stdout="""/usr/bin/python
python >= 2.4
python(abi) = 2.6
yum >= 3.2.29
/bin/sh
kernel = 2.6.32-279.14.1.el6_lustre
lustre-backend-fs
        """,
            ),
            CommandCaptureCommand((
                "yum",
                "install",
                "-y",
                "--exclude",
                "kernel-debug",
                "--enablerepo=myrepo",
                "foo",
                "kernel-2.6.32-279.14.1.el6_lustre",
            )),
            CommandCaptureCommand(("grubby", "--default-kernel"), rc=1),
        )

        def isfile(arg):
            return True

        with patch("os.path.isfile", side_effect=isfile):
            self.assertTrue(
                "error" in agent_updates.install_packages(["myrepo"], ["foo"]))

        self.assertRanAllCommandsInOrder()
Example #5
0
    def test_exported_unavailable_zpool_fail(self):
        """
        WHEN inactive zpool is unavailable,
        AND try to read zpool info from store fails,
        THEN no zpool is reported.
        """
        self.add_commands(
            CommandCaptureCommand(("udevadm", "settle")),
            CommandCaptureCommand(("zpool", "status"),
                                  stderr='no pools available\n'),
            CommandCaptureCommand(
                ("zpool", "import"),
                stdout=zfs_example_data.single_raidz2_unavail_pool))

        zfs_devices, block_devices = self._setup_zfs_devices(
            available_side_effect=[False])

        self.assertRanAllCommandsInOrder()
        self.mock_read_from_store.assert_called_once_with(
            '14729155358256179095')
        self.assertEqual(zfs_devices.zpools, {})
        self.assertEqual(zfs_devices.datasets, {})
        self.assertEqual(zfs_devices.zvols, {})

        self.assertDictEqual(block_devices.block_device_nodes, {})
Example #6
0
    def test_exported_unavailable_zpool_success(self):
        """
        WHEN inactive zpool is unavailable,
        AND try to read zpool info from store succeeds,
        THEN expected  are reported.
        """
        self.add_commands(
            CommandCaptureCommand(("udevadm", "settle")),
            CommandCaptureCommand(("zpool", "status"),
                                  stderr='no pools available\n'),
            CommandCaptureCommand(
                ("zpool", "import"),
                stdout=zfs_example_data.single_raidz2_unavail_pool_B))

        zfs_devices, block_devices = self._setup_zfs_devices(
            available_side_effect=[False])

        self.assertRanAllCommandsInOrder()
        self.mock_read_from_store.assert_called_once_with('222222222222222')
        self.assertEqual(zfs_devices.zpools, {})
        self.assertEqual(zfs_devices.datasets, zfs_results['datasets'])
        self.assertEqual(zfs_devices.zvols, zfs_results['zvols'])

        self.assertDictEqual(
            block_devices.block_device_nodes, {
                k: dev_results[k]
                for k in dev_results.keys() if k.startswith('zfsset')
            })
Example #7
0
    def test_lvm2_not_installed(self):
        self.add_commands(
            CommandCaptureCommand(('vgs', '--units', 'b', '--noheadings', '-o',
                                   'vg_name,vg_uuid,vg_size'),
                                  rc=self.CommandNotFound),
            CommandCaptureCommand(('dmsetup', 'table'),
                                  stdout="No devices found"))

        dm_setup_table = DmsetupTable({})

        self.assertEqual(dm_setup_table.vgs, {})
        self.assertEqual(dm_setup_table.lvs, {})

        self.assertRanAllCommandsInOrder()

        self.reset_command_capture()
        self.add_commands(
            CommandCaptureCommand(('vgs', '--units', 'b', '--noheadings', '-o',
                                   'vg_name,vg_uuid,vg_size'),
                                  rc=self.CommandNotFound),
            CommandCaptureCommand(('lvs', '--units', 'b', '--noheadings', '-o',
                                   'lv_name,lv_uuid,lv_size,lv_path', 'bob'),
                                  rc=self.CommandNotFound))

        for vgs in dm_setup_table._get_vgs():
            self.assertFalse(True, '_get_vgs did not deal with missing vgs')

        for lvs in dm_setup_table._get_lvs('bob'):
            self.assertFalse(True, '_get_lvs did not deal with missing lvg')

        self.assertRanAllCommandsInOrder()
Example #8
0
    def test_mkfs_no_mountpoint_option(self):
        """
        Check mountpoint is added to --mkfsoptions when parameter has been provided without mountpoint property
        assignment.
        """
        self.add_commands(
            CommandCaptureCommand(
                ("zpool", "set", "failmode=panic", "zpool1")),
            CommandCaptureCommand((
                "mkfs.lustre",
                "--mgs",
                "--backfstype=zfs",
                '--mkfsoptions="utf8only=on -o mountpoint=none"',
                "zpool1/MGS",
            )),
        )

        mkfs_options = [
            "--mgs", "--backfstype=zfs", '--mkfsoptions="utf8only=on"'
        ]

        self.assertEqual(
            self.filesystem.mkfs("MGS", mkfs_options),
            {
                "uuid": "123456789123",
                "filesystem_type": "zfs",
                "inode_size": None,
                "inode_count": None
            },
        )

        self.assertRanAllCommandsInOrder()

        self.uuid_prop_mock.assert_called_once()
        self.type_prop_mock.assert_called_once()
Example #9
0
    def test_close_port(self):
        # test closing a port, commands should be issued in order and the rule should be
        # removed from 'rules' member of FirewallControl class instance

        # add rule object so we can test it is removed when we issue the remove() command
        self.test_firewall.rules.append(self.example_port_rule)
        self.assertEqual(len(self.test_firewall.rules), 1)

        self.add_commands(
            CommandCaptureCommand(
                ('/usr/bin/firewall-cmd',
                 '--remove-port=%s/%s' % (self.port, self.proto))),
            CommandCaptureCommand(
                ('/usr/bin/firewall-cmd',
                 '--remove-port=%s/%s' % (self.port, self.proto),
                 '--permanent')))

        response = self.test_firewall.remove_rule(self.port,
                                                  self.proto,
                                                  self.desc,
                                                  persist=True)

        # None return value indicates success
        self.assertEqual(response, None)
        # rule should have been removed from list
        self.assertEqual(len(self.test_firewall.rules), 0)
        self.assertRanAllCommandsInOrder()
    def test_device_node_versions(self):
        for scsi_id in ["/sbin/scsi_id", "/lib/udev/scsi_id"]:
            # Check runs with correct scsi_id
            self.existing_files = [scsi_id]

            self.reset_command_capture()
            self.add_commands(
                CommandCaptureCommand(
                    ((scsi_id, '-g', '-p', '0x80', '/dev/blop'))),
                CommandCaptureCommand(
                    ((scsi_id, '-g', '-p', '0x83', '/dev/blop'))))

            result = self.block_devices._device_node(1, "/dev/blop", 1, None,
                                                     '1234')

            self.assertRanAllCommandsInOrder()

            self.assertEqual(
                result, {
                    'parent': None,
                    'major_minor': 1,
                    'serial_83': '',
                    'serial_80': '',
                    'path': '/dev/blop',
                    'filesystem_type': None,
                    'partition_number': '1234',
                    'size': 1
                })
Example #11
0
    def test_install_packages_4050_initramfs(self):
        self.add_commands(
            CommandCaptureCommand(('yum', 'clean', 'all', '--enablerepo=*')),
            CommandCaptureCommand(
                ('repoquery', '--requires', '--enablerepo=myrepo', 'foo'),
                stdout="""/usr/bin/python
python >= 2.4
python(abi) = 2.6
yum >= 3.2.29
/bin/sh
kernel = 2.6.32-279.14.1.el6_lustre
lustre-backend-fs
        """),
            CommandCaptureCommand(
                ('yum', 'install', '-y', '--exclude', 'kernel-debug',
                 '--enablerepo=myrepo', 'foo',
                 'kernel-2.6.32-279.14.1.el6_lustre')),
            CommandCaptureCommand(
                ('grubby', '--default-kernel'),
                stdout='/boot/vmlinuz-2.6.32-504.3.3.el6.x86_64'))

        def isfile(arg):
            return False

        with patch('os.path.isfile', side_effect=isfile):
            self.assertTrue(
                'error' in agent_updates.install_packages(['myrepo'], ['foo']))

        self.assertRanAllCommandsInOrder()
Example #12
0
    def test_failed_has_link(self):
        self.link_patcher.stop()

        mock.patch(
            'chroma_agent.lib.corosync.CorosyncRingInterface.__getattr__',
            return_value=False).start()

        import errno

        def boom(*args):
            # EMULTIHOP is what gets raised with IB interfaces
            raise IOError(errno.EMULTIHOP)

        mock.patch('fcntl.ioctl', side_effect=boom).start()

        from chroma_agent.lib.corosync import get_ring0
        iface = get_ring0()

        # add shell commands to be expected
        self.add_commands(
            CommandCaptureCommand(
                ('/sbin/ip', 'link', 'set', 'dev', iface.name, 'up')),
            CommandCaptureCommand(
                ('/sbin/ip', 'link', 'set', 'dev', iface.name, 'down')))

        self.assertFalse(iface.has_link)

        self.assertRanAllCommandsInOrder()
    def test_link_state_unknown(self):
        with mock.patch("__builtin__.open",
                        mock.mock_open(read_data="unknown")):
            with mock.patch(
                    "chroma_agent.lib.corosync.CorosyncRingInterface.__getattr__",
                    return_value=False,
            ):
                with mock.patch("os.path.exists", return_value=True):
                    self.link_patcher.stop()

                    from chroma_agent.lib.corosync import get_shared_ring

                    iface = get_shared_ring()

                    # add shell commands to be expected
                    self.add_commands(
                        CommandCaptureCommand(("/sbin/ip", "link", "set",
                                               "dev", iface.name, "up")),
                        CommandCaptureCommand(("/sbin/ip", "link", "set",
                                               "dev", iface.name, "down")),
                    )

                    self.assertFalse(iface.has_link)

                    self.assertRanAllCommandsInOrder()
    def test_failnode(self):
        self.add_commands(CommandCaptureCommand(("sync", ), 0, "", ""),
                          CommandCaptureCommand(("sync", ), 0, "", ""),
                          CommandCaptureCommand(("init", "0"), 0, "", ""))

        fail_node([])
        self.assertRanAllCommandsInOrder()
Example #15
0
    def test_stop_should_be_idempotent1(self):
        self.single_commands(
            CommandCaptureCommand(("systemctl", "is-active",
                                   "chroma-copytool-monitor-%s" % self.ct_id)),
            CommandCaptureCommand(("systemctl", "stop",
                                   "chroma-copytool-monitor-%s" % self.ct_id)),
            CommandCaptureCommand(
                ("systemctl", "is-active",
                 "chroma-copytool-monitor-%s" % self.ct_id),
                rc=1,
            ),
            CommandCaptureCommand(("systemctl", "daemon-reload")),
            CommandCaptureCommand(
                ("systemctl", "is-active", "chroma-copytool-%s" % self.ct_id)),
            CommandCaptureCommand(
                ("systemctl", "stop", "chroma-copytool-%s" % self.ct_id)),
            CommandCaptureCommand(
                ("systemctl", "is-active", "chroma-copytool-%s" % self.ct_id),
                rc=1),
            CommandCaptureCommand(("systemctl", "daemon-reload")),
            CommandCaptureCommand(("systemctl", "daemon-reload")),
            CommandCaptureCommand(("systemctl", "daemon-reload")),
        )

        with mock.patch("os.path.exists", return_value=True):
            self.assertAgentOK(stop_monitored_copytool(self.ct_id))

        with mock.patch("os.path.exists", return_value=False):
            self.assertAgentOK(stop_monitored_copytool(self.ct_id))

        self.assertRanAllCommandsInOrder()
Example #16
0
    def test_corosync_causes_session_to_reestablish(self):
        """Connecting to crm_mon fails

        Could not establish cib_ro connection: Connection refused rc=107

        This represents any case that is unknown; which is rc: 0, 10.  In this
        case, the response should be treated like an SPI boundary.  This means
        log it and re-raise.  But, raising is what causes the trashing, so
        instead just return None

        see also:  https://jira.hpdd.intel.com/browse/HYD-1914

        """

        #  Simulate crm_mon returning an unexpected error code
        self.add_commands(
            CommandCaptureCommand(CMD, rc=107),
            CommandCaptureCommand(('service', 'corosync', 'status'), rc=1),
            CommandCaptureCommand(('service', 'pacemaker', 'status'), rc=1))

        plugin = CorosyncPlugin(None)
        result_dict = plugin.start_session()

        self.assertEqual(result_dict["state"]["corosync"], 'stopped')
        self.assertEqual(result_dict["state"]["pacemaker"], 'stopped')
        self.assertEqual(result_dict["crm_info"], None)
        self.assertRanAllCommandsInOrder()
Example #17
0
    def test_mkfs_no_mkfsoptions(self):
        """
        Check --mkfsoptions are added to list of parameters provided to mkfs.lustre command when some parameters have
        been provided.
        """
        self.add_commands(
            CommandCaptureCommand(
                ("zpool", "set", "failmode=panic", "zpool1")),
            CommandCaptureCommand(
                ("mkfs.lustre", "--mgs", "--backfstype=zfs",
                 '--mkfsoptions="mountpoint=none"', "zpool1/MGS")),
        )

        mkfs_options = ["--mgs", "--backfstype=zfs"]

        self.assertEqual(
            self.filesystem.mkfs("MGS", mkfs_options),
            {
                "uuid": "123456789123",
                "filesystem_type": "zfs",
                "inode_size": None,
                "inode_count": None
            },
        )

        self.assertRanAllCommandsInOrder()

        self.uuid_prop_mock.assert_called_once()
        self.type_prop_mock.assert_called_once()
Example #18
0
    def test_corosync_down(self):
        """Corosync is not running - attempt was tried, but failed.

        There is no data to return other then an error message

        { 'ERROR':  'Connection to cluster failed: connection failed' }
        """
        from chroma_agent.device_plugins.corosync import CorosyncPlugin

        self.add_commands(
            CommandCaptureCommand(
                CMD,
                rc=10,
                stdout="""Connection to cluster failed: connection failed"""),
            CommandCaptureCommand(("systemctl", "is-active", "corosync"),
                                  rc=1),
            CommandCaptureCommand(("systemctl", "is-active", "pacemaker"),
                                  rc=1),
        )

        plugin = CorosyncPlugin(None)
        result_dict = plugin.start_session()

        self.assertEqual(result_dict["state"]["corosync"], "stopped")
        self.assertEqual(result_dict["state"]["pacemaker"], "stopped")
        self.assertEqual(result_dict["crm_info"], None)
        self.assertRanAllCommandsInOrder()
Example #19
0
    def test_resolve_devices_multiple_matches(self):
        """
        Check when zpool contains device basenames which are a substring of another, the listed partitions are
        resolved to the correct devices
        """
        self.add_commands(
            CommandCaptureCommand(
                ("zpool", "list", "-PHv", "-o", "name", "zfsPool1"),
                stdout="""\
zfsPool1
        /dev/a/dev1111   9.94G   228K    9.94G   -       0%      0%
        /dev/b/dev111   9.94G   228K    9.94G   -       0%      0%
        /dev/c/dev11   9.94G   228K    9.94G   -       0%      0%
        /dev/d/dev1   9.94G   228K    9.94G   -       0%      0%
        /dev/disk/by-id2/md0-0011   9.94G   228K    9.94G   -       0%      0%
        /dev/disk/by-id1/md0-00111   9.94G   228K    9.94G   -       0%      0%\n"""
            ),
            CommandCaptureCommand(
                ("zpool", "list", "-Hv", "-o", "name", "zfsPool1"),
                stdout="""\
zfsPool1
        dev   9.94G   228K    9.94G   -       0%      0%
        dev1   9.94G   228K    9.94G   -       0%      0%
        dev11   9.94G   228K    9.94G   -       0%      0%
        dev111   9.94G   228K    9.94G   -       0%      0%
        md0-0011   9.94G   228K    9.94G   -       0%      0%
        md0-001   9.94G   228K    9.94G   -       0%      0%\n"""))

        self.assertItemsEqual(self._get_zfs_devices('zfsPool1'), [
            '/dev/disk/by-id1/md0-0011', '/dev/disk/by-id2/md0-001',
            '/dev/d/dev', '/dev/c/dev1', '/dev/b/dev11', '/dev/a/dev111'
        ])
        self.assertRanAllCommandsInOrder()
    def test_stop_should_be_idempotent2(self):
        self.single_commands(CommandCaptureCommand(('systemctl', 'is-active', 'chroma-copytool-monitor-%s' % self.ct_id), rc=1),
                             CommandCaptureCommand(('systemctl', 'daemon-reload')),
                             CommandCaptureCommand(('systemctl', 'is-active', 'chroma-copytool-%s' % self.ct_id), rc=1),
                             CommandCaptureCommand(('systemctl', 'daemon-reload')))

        with mock.patch('os.path.exists', return_value=True):
            self.assertAgentOK(stop_monitored_copytool(self.ct_id))

        self.assertRanAllCommandsInOrder()
    def test_mount_fail_second(self):
        """ Test when initial mount fails and the retry fails, exception is raised """
        self.add_commands(CommandCaptureCommand(('mount', '-t', 'lustre', '/dev/sda1', '/mnt/OST0000'), rc=5,
                                                executions_remaining=1),
                          CommandCaptureCommand(('mount', '-t', 'lustre', '/dev/sda1', '/mnt/OST0000'), rc=5,
                                                executions_remaining=1))

        self.assertRaises(RuntimeError, self.filesystem.mount, '/mnt/OST0000')

        self.assertRanAllCommandsInOrder()
    def _mount_fail_initial(self, fail_code):
        """ Test when initial mount fails, retry succeeds and result returned """
        self.add_commands(CommandCaptureCommand(('mount', '-t', 'lustre', '/dev/sda1', '/mnt/OST0000'), rc=fail_code,
                                                executions_remaining=1),
                          CommandCaptureCommand(('mount', '-t', 'lustre', '/dev/sda1', '/mnt/OST0000'), rc=0,
                                                executions_remaining=1))

        self.filesystem.mount('/mnt/OST0000')

        self.assertRanAllCommandsInOrder()
Example #23
0
    def test_stop_monitored_copytool(self):
        self.single_commands(
            CommandCaptureCommand(("systemctl", "is-active",
                                   "chroma-copytool-monitor-%s" % self.ct_id)),
            CommandCaptureCommand(("systemctl", "stop",
                                   "chroma-copytool-monitor-%s" % self.ct_id)),
            CommandCaptureCommand(
                ("systemctl", "is-active",
                 "chroma-copytool-monitor-%s" % self.ct_id),
                rc=1,
            ),
            CommandCaptureCommand(("systemctl", "daemon-reload")),
            CommandCaptureCommand(
                ("systemctl", "is-active", "chroma-copytool-%s" % self.ct_id)),
            CommandCaptureCommand(
                ("systemctl", "stop", "chroma-copytool-%s" % self.ct_id)),
            CommandCaptureCommand(
                ("systemctl", "is-active", "chroma-copytool-%s" % self.ct_id),
                rc=1),
            CommandCaptureCommand(("systemctl", "daemon-reload")),
        )

        with mock.patch("os.path.exists", return_value=True):
            self.assertAgentOK(stop_monitored_copytool(self.ct_id))

        self.assertRanAllCommandsInOrder()
        self.assertEqual(self.mock_os_remove.call_count, 2)
        self.mock_os_remove.assert_called_with(
            "/etc/init.d/chroma-copytool-%s" % self.ct_id)
    def test_mkfs(self):
        """ Test returning the correct parameters from mkfs call. Test also partly covers inode methods """
        self.add_commands(CommandCaptureCommand(('mkfs.lustre', '/dev/sda1')),
                          CommandCaptureCommand(('dumpe2fs', '-h', self.filesystem._device_path),
                                                stdout=example_data.dumpe2fs_example_output),
                          CommandCaptureCommand(('dumpe2fs', '-h', self.filesystem._device_path),
                                                stdout=example_data.dumpe2fs_example_output))

        self.assertEqual(self.filesystem.mkfs(None, []),
                         {'uuid': '123456789123',
                          'filesystem_type': 'ldiskfs',
                          'inode_size': 128,
                          'inode_count': 128016})

        self.assertRanAllCommandsInOrder()
Example #25
0
    def setUp(self):
        super(TestFenceAgent, self).setUp()

        self.fake_node_attributes = {'0_fence_agent': 'fence_apc',
                                     '0_fence_login': '******',
                                     '0_fence_password': '******',
                                     '0_fence_ipaddr': '1.2.3.4',
                                     '0_fence_plug': '1'}

        call_template = "%(0_fence_agent)s -a %(0_fence_ipaddr)s -u 23 -l %(0_fence_login)s -p %(0_fence_password)s -n %(0_fence_plug)s" % self.fake_node_attributes
        call_base = tuple(call_template.split())

        self.add_commands(CommandCaptureCommand(('cibadmin', '--query', '--local')),
                          CommandCaptureCommand((call_base + ('-o', 'off'))),
                          CommandCaptureCommand((call_base + ('-o', 'on'))))
    def test_mkfs_no_options(self):
        """
        Check --mkfsoptions are added to list of parameters provided to mkfs.lustre command when no parameters
        have been provided.
        """
        self.add_commands(CommandCaptureCommand(('zpool', 'set', 'failmode=panic', 'zpool1')),
                          CommandCaptureCommand(('mkfs.lustre', '--mkfsoptions="mountpoint=none"', 'zpool1/MGS')))

        self.assertEqual(self.filesystem.mkfs('MGS', self.filesystem.mkfs_options(None)),
                         {'uuid': '123456789123', 'filesystem_type': 'zfs', 'inode_size': None, 'inode_count': None})

        self.assertRanAllCommandsInOrder()

        self.uuid_prop_mock.assert_called_once()
        self.type_prop_mock.assert_called_once()
    def _mount_fail_initial(self, fail_code):
        """ Test when initial mount fails, retry succeeds and result returned """
        self.add_commands(
            CommandCaptureCommand(
                ("mount", "-t", "lustre", "/dev/sda1", "/mnt/OST0000"),
                rc=fail_code,
                executions_remaining=1),
            CommandCaptureCommand(
                ("mount", "-t", "lustre", "/dev/sda1", "/mnt/OST0000"),
                rc=0,
                executions_remaining=1),
        )

        self.filesystem.mount("/mnt/OST0000")

        self.assertRanAllCommandsInOrder()
Example #28
0
    def test_close_address(self):
        # test remove_rule with address removes relevant rule from the class instance 'rules' list,
        # also test correct shell command is issued

        # add rule object so we can test it is removed when we issue the remove() command
        self.test_firewall.rules.append(self.example_address_rule)
        self.assertEqual(len(self.test_firewall.rules), 1)

        self.add_commands(
            CommandCaptureCommand(
                ('/usr/bin/firewall-cmd', '--remove-rich-rule='
                 'rule family="ipv4" '
                 'destination address="%s" '
                 'protocol value="%s" '
                 'accept' % (self.address, self.proto))))

        response = self.test_firewall.remove_rule(0,
                                                  self.proto,
                                                  self.desc,
                                                  persist=False,
                                                  address=self.address)

        # None return value indicates success
        self.assertEqual(response, None)
        # rule should have been removed from list
        self.assertEqual(len(self.test_firewall.rules), 0)
        self.assertRanAllCommandsInOrder()
Example #29
0
    def test_unmanage_network_nm_running(self):
        self.add_commands(CommandCaptureCommand(('nmcli', 'con', 'load', self.write_ifcfg_result)))

        node_admin.unmanage_network(self.device_name, self.mac_address)

        self.assertRanAllCommandsInOrder()
        self.write_ifcfg_mock.assert_called_with(self.device_name, self.mac_address, None, None)
    def test_check_module(self):
        self.patch_init_modules.stop()

        self.add_commands(CommandCaptureCommand(('/usr/sbin/udevadm', 'info', '--path=/module/ldiskfs')))

        self.filesystem._check_module()

        self.assertRanAllCommandsInOrder()