Ejemplo n.º 1
0
def dist_upgrade(unit_name):
    """Run dist-upgrade on unit after update package db.

    :param unit_name: Unit Name
    :type unit_name: str
    :returns: None
    :rtype: None
    """
    logging.info('Updating package db ' + unit_name)
    update_cmd = 'sudo apt update'
    model.run_on_unit(unit_name, update_cmd)

    logging.info('Updating existing packages ' + unit_name)
    dist_upgrade_cmd = (
        """sudo DEBIAN_FRONTEND=noninteractive apt --assume-yes """
        """-o "Dpkg::Options::=--force-confdef" """
        """-o "Dpkg::Options::=--force-confold" dist-upgrade""")
    model.run_on_unit(unit_name, dist_upgrade_cmd)
    rdict = model.run_on_unit(unit_name, "cat /var/run/reboot-required")
    if "Stdout" in rdict and "restart" in rdict["Stdout"].lower():
        logging.info("dist-upgrade required reboot {}".format(unit_name))
        os_utils.reboot(unit_name)
        logging.info("Waiting for workload status 'unknown' on {}"
                     .format(unit_name))
        model.block_until_unit_wl_status(unit_name, "unknown")
        logging.info("Waiting for workload status to return to normal on {}"
                     .format(unit_name))
        model.block_until_unit_wl_status(
            unit_name, "unknown", negate_match=True)
        logging.info("Waiting for model idleness")
        # pause for a big
        time.sleep(5.0)
        model.block_until_all_units_idle()
Ejemplo n.º 2
0
    def test_block_until_unit_wl_status_fail(self):
        async def _block_until(f, timeout=None):
            rc = await f()
            if not rc:
                raise asyncio.futures.TimeoutError

        async def _get_status():
            return self.juju_status

        (self.juju_status.applications[self.application]
            ["units"][self.unit]["workload-status"]["status"]) = "blocked"

        self.patch_object(model, 'Model')
        self.Model.return_value = self.Model_mock
        self.patch_object(model, 'get_juju_model', return_value='mname')
        self.patch_object(model, 'get_unit_from_name')
        self.patch_object(model, 'async_get_status')
        self.async_get_status.side_effect = _get_status
        self.patch_object(model, 'async_block_until')
        self.async_block_until.side_effect = _block_until
        with self.assertRaises(asyncio.futures.TimeoutError):
            model.block_until_unit_wl_status(
                'app/1',
                'active',
                timeout=0.1)
Ejemplo n.º 3
0
    def test_list_disks(self):
        """Test the list-disks action.

        The list-disks action execute.
        """
        logging.info('Checking list-disks action...')
        unit_name = 'ceph-osd/0'

        zaza_model.block_until_unit_wl_status(unit_name, 'active')

        action_obj = zaza_model.run_action(
            unit_name=unit_name,
            action_name='list-disks',
        )
        self.assertEqual('completed', action_obj.status)
        zaza_model.block_until_unit_wl_status(unit_name, 'active')
        logging.debug('OK')
Ejemplo n.º 4
0
    def test_block_until_unit_wl_status(self):
        async def _block_until(f, timeout=None):
            rc = await f()
            if not rc:
                raise asyncio.futures.TimeoutError

        async def _get_status():
            return self.juju_status

        self.patch_object(model, 'Model')
        self.Model.return_value = self.Model_mock
        self.patch_object(model, 'get_juju_model', return_value='mname')
        self.patch_object(model, 'get_unit_from_name')
        self.patch_object(model, 'async_get_status')
        self.async_get_status.side_effect = _get_status
        self.patch_object(model, 'async_block_until')
        self.async_block_until.side_effect = _block_until
        model.block_until_unit_wl_status('app/1', 'active', timeout=0.1)
Ejemplo n.º 5
0
    def test_blacklist(self):
        """Check the blacklist action.

        The blacklist actions execute and behave as expected.
        """
        logging.info('Checking blacklist-add-disk and'
                     'blacklist-remove-disk actions...')
        unit_name = 'ceph-osd/0'

        zaza_model.block_until_unit_wl_status(unit_name, 'active')

        # Attempt to add device with non-absolute path should fail
        action_obj = zaza_model.run_action(
            unit_name=unit_name,
            action_name='blacklist-add-disk',
            action_params={'osd-devices': 'vda'})
        self.assertTrue(action_obj.status != 'completed')
        zaza_model.block_until_unit_wl_status(unit_name, 'active')

        # Attempt to add device with non-existent path should fail
        action_obj = zaza_model.run_action(
            unit_name=unit_name,
            action_name='blacklist-add-disk',
            action_params={'osd-devices': '/non-existent'})
        self.assertTrue(action_obj.status != 'completed')
        zaza_model.block_until_unit_wl_status(unit_name, 'active')

        # Attempt to add device with existent path should succeed
        action_obj = zaza_model.run_action(
            unit_name=unit_name,
            action_name='blacklist-add-disk',
            action_params={'osd-devices': '/dev/vda'})
        self.assertEqual('completed', action_obj.status)
        zaza_model.block_until_unit_wl_status(unit_name, 'active')

        # Attempt to remove listed device should always succeed
        action_obj = zaza_model.run_action(
            unit_name=unit_name,
            action_name='blacklist-remove-disk',
            action_params={'osd-devices': '/dev/vda'})
        self.assertEqual('completed', action_obj.status)
        zaza_model.block_until_unit_wl_status(unit_name, 'active')
        logging.debug('OK')
Ejemplo n.º 6
0
    def osd_out_in(self, services):
        """Run OSD out and OSD in tests.

        Remove OSDs and then add them back in on a unit checking that services
        are in the required state after each action

        :param services: Services expected to be restarted when config_file is
                         changed.
        :type services: list
        """
        zaza_model.block_until_service_status(self.lead_unit,
                                              services,
                                              'running',
                                              model_name=self.model_name)
        zaza_model.block_until_unit_wl_status(self.lead_unit,
                                              'active',
                                              model_name=self.model_name)
        zaza_model.run_action(self.lead_unit,
                              'osd-out',
                              model_name=self.model_name)
        zaza_model.block_until_unit_wl_status(self.lead_unit,
                                              'maintenance',
                                              model_name=self.model_name)
        zaza_model.block_until_all_units_idle(model_name=self.model_name)
        zaza_model.run_action(self.lead_unit,
                              'osd-in',
                              model_name=self.model_name)
        zaza_model.block_until_unit_wl_status(self.lead_unit,
                                              'active',
                                              model_name=self.model_name)
        zaza_model.block_until_all_units_idle(model_name=self.model_name)
        zaza_model.block_until_service_status(self.lead_unit,
                                              services,
                                              'running',
                                              model_name=self.model_name)
Ejemplo n.º 7
0
def series_upgrade(unit_name, machine_num,
                   from_series="trusty", to_series="xenial",
                   origin='openstack-origin',
                   files=None, workaround_script=None):
    """Perform series upgrade on a unit.

    :param unit_name: Unit Name
    :type unit_name: str
    :param machine_num: Machine number
    :type machine_num: str
    :param from_series: The series from which to upgrade
    :type from_series: str
    :param to_series: The series to which to upgrade
    :type to_series: str
    :param origin: The configuration setting variable name for changing origin
                   source. (openstack-origin or source)
    :type origin: str
    :param files: Workaround files to scp to unit under upgrade
    :type files: list
    :param workaround_script: Workaround script to run during series upgrade
    :type workaround_script: str
    :returns: None
    :rtype: None
    """
    logging.info("Series upgrade {}".format(unit_name))
    application = unit_name.split('/')[0]
    set_dpkg_non_interactive_on_unit(unit_name)
    logging.info("Prepare series upgrade on {}".format(machine_num))
    model.prepare_series_upgrade(machine_num, to_series=to_series)
    logging.info("Waiting for workload status 'blocked' on {}"
                 .format(unit_name))
    model.block_until_unit_wl_status(unit_name, "blocked")
    logging.info("Waiting for model idleness")
    model.block_until_all_units_idle()
    wrap_do_release_upgrade(unit_name, from_series=from_series,
                            to_series=to_series, files=files,
                            workaround_script=workaround_script)
    logging.info("Reboot {}".format(unit_name))
    reboot(unit_name)
    logging.info("Waiting for workload status 'blocked' on {}"
                 .format(unit_name))
    model.block_until_unit_wl_status(unit_name, "blocked")
    logging.info("Waiting for model idleness")
    model.block_until_all_units_idle()
    logging.info("Set origin on {}".format(application))
    # Allow for charms which have neither source nor openstack-origin
    if origin:
        set_origin(application, origin)
    model.block_until_all_units_idle()
    logging.info("Complete series upgrade on {}".format(machine_num))
    model.complete_series_upgrade(machine_num)
    model.block_until_all_units_idle()
    logging.info("Waiting for workload status 'active' on {}"
                 .format(unit_name))
    model.block_until_unit_wl_status(unit_name, "active")
    model.block_until_all_units_idle()
    # This step may be performed by juju in the future
    logging.info("Set series on {} to {}".format(application, to_series))
    model.set_series(application, to_series)
Ejemplo n.º 8
0
    def pause_resume(self, services, pgrep_full=False):
        """Run Pause and resume tests.

        Pause and then resume a unit checking that services are in the
        required state after each action

        :param services: Services expected to be restarted when config_file is
                         changed.
        :type services: list
        :param pgrep_full: Should pgrep be used rather than pidof to identify
                           a service.
        :type  pgrep_full: bool
        """
        model.block_until_service_status(
            self.lead_unit,
            services,
            'running',
            model_name=self.model_name,
            pgrep_full=pgrep_full)
        model.block_until_unit_wl_status(
            self.lead_unit,
            'active',
            model_name=self.model_name)
        model.run_action(
            self.lead_unit,
            'pause',
            model_name=self.model_name)
        model.block_until_unit_wl_status(
            self.lead_unit,
            'maintenance',
            model_name=self.model_name)
        model.block_until_all_units_idle(model_name=self.model_name)
        model.block_until_service_status(
            self.lead_unit,
            services,
            'stopped',
            model_name=self.model_name,
            pgrep_full=pgrep_full)
        yield
        model.run_action(
            self.lead_unit,
            'resume',
            model_name=self.model_name)
        model.block_until_unit_wl_status(
            self.lead_unit,
            'active',
            model_name=self.model_name)
        model.block_until_all_units_idle(model_name=self.model_name)
        model.block_until_service_status(
            self.lead_unit,
            services,
            'running',
            model_name=self.model_name,
            pgrep_full=pgrep_full)
Ejemplo n.º 9
0
    def pause_resume(self, services):
        """Run Pause and resume tests.

        Override the default implementation since pausing ceph units
        doesn't stop the services.
        Pause and then resume a unit checking that services are in the
        required state after each action

        :param services: Services expected to be restarted when config_file is
                         changed.
        :type services: list
        """
        zaza_model.block_until_service_status(self.lead_unit,
                                              services,
                                              'running',
                                              model_name=self.model_name)
        zaza_model.block_until_unit_wl_status(self.lead_unit,
                                              'active',
                                              model_name=self.model_name)
        zaza_model.run_action(self.lead_unit,
                              'pause',
                              model_name=self.model_name)
        zaza_model.block_until_unit_wl_status(self.lead_unit,
                                              'maintenance',
                                              model_name=self.model_name)
        zaza_model.block_until_all_units_idle(model_name=self.model_name)
        zaza_model.run_action(self.lead_unit,
                              'resume',
                              model_name=self.model_name)
        zaza_model.block_until_unit_wl_status(self.lead_unit,
                                              'active',
                                              model_name=self.model_name)
        zaza_model.block_until_all_units_idle(model_name=self.model_name)
        zaza_model.block_until_service_status(self.lead_unit,
                                              services,
                                              'running',
                                              model_name=self.model_name)
Ejemplo n.º 10
0
    def pause_resume(self, services):
        """Run Pause and resume tests.

        Pause and then resume a unit checking that services are in the
        required state after each action

        :param services: Services expected to be restarted when config_file is
                         changed.
        :type services: list
        """
        model.block_until_service_status(self.lead_unit,
                                         services,
                                         'running',
                                         model_name=self.model_name)
        model.block_until_unit_wl_status(self.lead_unit,
                                         'active',
                                         model_name=self.model_name)
        model.run_action(self.lead_unit, 'pause', model_name=self.model_name)
        model.block_until_unit_wl_status(self.lead_unit,
                                         'maintenance',
                                         model_name=self.model_name)
        model.block_until_all_units_idle(model_name=self.model_name)
        model.block_until_service_status(self.lead_unit,
                                         services,
                                         'stopped',
                                         model_name=self.model_name)
        yield
        model.run_action(self.lead_unit, 'resume', model_name=self.model_name)
        model.block_until_unit_wl_status(self.lead_unit,
                                         'active',
                                         model_name=self.model_name)
        model.block_until_all_units_idle(model_name=self.model_name)
        model.block_until_service_status(self.lead_unit,
                                         services,
                                         'running',
                                         model_name=self.model_name)