Exemplo n.º 1
0
def set_profile(profile_json):
    profile = json.loads(profile_json)

    try:
        config.set('settings', 'profile', profile)
    except ConfigKeyExistsError:
        config.update('settings', 'profile', profile)
Exemplo n.º 2
0
    def test_set_profile_success(self):
        config.update("settings", "profile", {"managed": False})

        # Go from managed = False to managed = True
        self.add_command((
            "yum",
            "install",
            "-y",
            "--exclude",
            "kernel-debug",
            "python2-iml-agent-management",
        ))
        self.assertEqual(agent_updates.update_profile({"managed": True}),
                         agent_result_ok)
        self.assertRanAllCommandsInOrder()

        # Go from managed = True to managed = False
        self.reset_command_capture()
        self.add_command(
            ("yum", "remove", "-y", "python2-iml-agent-management"))
        self.assertEqual(agent_updates.update_profile({"managed": False}),
                         agent_result_ok)
        self.assertRanAllCommandsInOrder()

        # Go from managed = False to managed = False
        self.reset_command_capture()
        self.assertEqual(agent_updates.update_profile({"managed": False}),
                         agent_result_ok)
        self.assertRanAllCommandsInOrder()
Exemplo n.º 3
0
    def test_set_profile_fail(self):
        # Three times because yum will try three times.
        self.add_commands(
            CommandCaptureCommand(
                ('yum', 'install', '-y', '--exclude', 'kernel-debug',
                 'python2-iml-agent-management'),
                rc=1,
                stdout="Bad command stdout",
                stderr="Bad command stderr"),
            CommandCaptureCommand(('yum', 'clean', 'metadata')),
            CommandCaptureCommand(
                ('yum', 'install', '-y', '--exclude', 'kernel-debug',
                 'python2-iml-agent-management'),
                rc=1,
                stdout="Bad command stdout",
                stderr="Bad command stderr"),
            CommandCaptureCommand(('yum', 'clean', 'metadata')),
            CommandCaptureCommand(
                ('yum', 'install', '-y', '--exclude', 'kernel-debug',
                 'python2-iml-agent-management'),
                rc=1,
                stdout="Bad command stdout",
                stderr="Bad command stderr"),
            CommandCaptureCommand(('yum', 'clean', 'metadata')))

        config.update('settings', 'profile', {'managed': False})

        # Go from managed = False to managed = True, but it will fail.
        self.assertEqual(
            agent_updates.update_profile({'managed': True}),
            agent_error(
                'Unable to set profile because yum returned Bad command stdout'
            ))
        self.assertRanAllCommandsInOrder()
Exemplo n.º 4
0
def set_profile(profile_json):
    profile = json.loads(profile_json)

    try:
        config.set('settings', 'profile', profile)
        set_iml_profile(profile.name, profile.bundles, profile.packages)
    except ConfigKeyExistsError:
        config.update('settings', 'profile', profile)
Exemplo n.º 5
0
def _get_target_config(uuid):
    info = config.get('targets', uuid)

    # Some history, previously the backfstype, device_type was not stored so if not present presume ldiskfs/linux
    if ('backfstype' not in info) or ('device_type' not in info):
        info['backfstype'] = info.get('backfstype', 'ldiskfs')
        info['device_type'] = info.get('device_type', 'linux')
        config.update('targets', uuid, info)
    return info
Exemplo n.º 6
0
    def test_set_profile_fail(self):
        # Three times because yum will try three times.
        self.add_commands(
            CommandCaptureCommand(
                (
                    "yum",
                    "install",
                    "-y",
                    "--exclude",
                    "kernel-debug",
                    "python2-iml-agent-management",
                ),
                rc=1,
                stdout="Bad command stdout",
                stderr="Bad command stderr",
            ),
            CommandCaptureCommand(("yum", "clean", "metadata")),
            CommandCaptureCommand(
                (
                    "yum",
                    "install",
                    "-y",
                    "--exclude",
                    "kernel-debug",
                    "python2-iml-agent-management",
                ),
                rc=1,
                stdout="Bad command stdout",
                stderr="Bad command stderr",
            ),
            CommandCaptureCommand(("yum", "clean", "metadata")),
            CommandCaptureCommand(
                (
                    "yum",
                    "install",
                    "-y",
                    "--exclude",
                    "kernel-debug",
                    "python2-iml-agent-management",
                ),
                rc=1,
                stdout="Bad command stdout",
                stderr="Bad command stderr",
            ),
            CommandCaptureCommand(("yum", "clean", "metadata")),
        )

        config.update("settings", "profile", {"managed": False})

        # Go from managed = False to managed = True, but it will fail.
        self.assertEqual(
            agent_updates.update_profile({"managed": True}),
            agent_error(
                "Unable to set profile because yum returned Bad command stdout"
            ),
        )
        self.assertRanAllCommandsInOrder()
Exemplo n.º 7
0
def update_profile(profile):
    """
    Sets the profile to the profile_name by fetching the profile from the manager
    :param profile_name:
    :return: error or result OK
    """
    config.update("settings", "profile", profile)

    return agent_result_ok
Exemplo n.º 8
0
def _get_target_config(uuid):
    info = config.get("targets", uuid)

    # Some history, previously the backfstype, device_type was not stored so if
    # not present presume ldiskfs/linux
    if ("backfstype" not in info) or ("device_type" not in info):
        info["backfstype"] = info.get("backfstype", "ldiskfs")
        info["device_type"] = info.get("device_type", "linux")
        config.update("targets", uuid, info)
    return info
Exemplo n.º 9
0
def set_profile(profile_json):
    profile = json.loads(profile_json)

    try:
        config.set("settings", "profile", profile)
    except ConfigKeyExistsError:
        config.update("settings", "profile", profile)

    set_iml_profile(profile.get("name"), profile.get("bundles"),
                    profile.get("packages"))
Exemplo n.º 10
0
def configure_target_store(device, uuid, mount_point, backfstype, device_type):
    # Logically this should be config.set - but an error condition exists where the configure_target_store
    # steps fail later on and so the config exists but the manager doesn't know. Meaning that a set fails
    # because of a duplicate, where as an update doesn't.
    # So use update because that updates or creates.
    config.update(
        'targets', uuid, {
            'bdev': device,
            'mntpt': mount_point,
            'backfstype': backfstype,
            'device_type': device_type
        })
Exemplo n.º 11
0
def configure_target_store(device, uuid, mount_point, backfstype, device_type):
    # Logically this should be config.set - but an error condition exists where the
    # configure_target_store steps fail later on and so the config exists but the manager doesn't
    # know. Meaning that a set fails because of a duplicate, where as an update doesn't.  So use
    # update because that updates or creates.
    _mkdir_p_concurrent(mount_point)
    config.update(
        "targets",
        uuid,
        {
            "bdev": device,
            "mntpt": mount_point,
            "backfstype": backfstype,
            "device_type": device_type,
        },
    )
Exemplo n.º 12
0
    def test_set_profile_success(self):
        config.update('settings', 'profile', {'managed': False})

        # Go from managed = False to managed = True
        self.add_command(('yum', 'install', '-y', '--enablerepo=iml-agent', 'chroma-agent-management'))
        self.assertEqual(agent_updates.update_profile({'managed': True}), agent_result_ok)
        self.assertRanAllCommandsInOrder()

        # Go from managed = True to managed = False
        self.reset_command_capture()
        self.add_command(('yum', 'remove', '-y', '--enablerepo=iml-agent', 'chroma-agent-management'))
        self.assertEqual(agent_updates.update_profile({'managed': False}), agent_result_ok)
        self.assertRanAllCommandsInOrder()

        # Go from managed = False to managed = False
        self.reset_command_capture()
        self.assertEqual(agent_updates.update_profile({'managed': False}), agent_result_ok)
        self.assertRanAllCommandsInOrder()
Exemplo n.º 13
0
def detect_scan(target_devices=None):
    """Look for Lustre on possible devices

    Save the input devices when possible.  Then future calls will
    not need to specify the target_devices
    """

    right_now = str(datetime.now())

    if target_devices is not None:
        target_devices_time_stamped = dict(timestamp=right_now,
                                           target_devices=target_devices)
        config.update('settings', 'last_detect_scan_target_devices',
                      target_devices_time_stamped)

    try:
        # Recall the last target_devices used in this method
        settings = config.get('settings', 'last_detect_scan_target_devices')
    except KeyError:
        # This method was never called with a non-null target_devices
        # or the setting file holding the device record is not found.
        daemon_log.warn("detect_scan improperly called without target_devices "
                        "and without a previous call's target_devices to use.")

        # TODO: Consider an exception here. But, since this is a rare case, it seems reasonable to return emptiness
        # TODO: If this raised an exception, it should be a handled one in any client, and that seems too heavy
        local_targets = LocalTargets([])
        timestamp = right_now

    else:
        # Have target devices, so process them
        timestamp = settings['timestamp']
        daemon_log.info(
            "detect_scan called at %s with target_devices saved on %s" %
            (str(datetime.now()), timestamp))
        local_targets = LocalTargets(settings['target_devices'])

    # Return the discovered Lustre components on the target devices, may return emptiness.
    mgs_targets = MgsTargets(local_targets.targets)
    return {
        "target_devices_saved_timestamp": timestamp,
        "local_targets": local_targets.targets,
        "mgs_targets": mgs_targets.filesystems
    }
Exemplo n.º 14
0
def update_profile(profile):
    '''
    Sets the profile to the profile_name by fetching the profile from the manager
    :param profile_name:
    :return: error or result OK
    '''
    old_profile = config.get('settings', 'profile')
    '''
    This is an incomplete solution but the incompleteness is at the bottom of the stack and we need this as a fix up
    for 2.2 release.

    What really needs to happen here is that the profile contains the name of the packages to install and then this
    code would diff the old list and the new list and remove and add appropriately. For now we are just going to do that
    in a hard coded way using the managed property.

    To do this properly the profile needs to contain the packages and the endpoint needs to return them. We are going to
    need it and when we do this function and profiles will need to be extended.

    This code might want to use the update_pacakges as well but it's not clear and we are in a pickle here. This code is
    not bad and doesn't have bad knock on effects.
    '''

    if old_profile['managed'] != profile['managed']:
        if profile['managed']:
            action = 'install'
        else:
            action = 'remove'

        try:
            yum_util(action,
                     enablerepo=["iml-agent"],
                     packages=['chroma-agent-management'])
        except AgentShell.CommandExecutionError as cee:
            return agent_error(
                "Unable to set profile because yum returned %s" %
                cee.result.stdout)

    config.update('settings', 'profile', profile)

    return agent_result_ok
Exemplo n.º 15
0
    def test_set_profile_success(self):
        config.update('settings', 'profile', {'managed': False})

        # Go from managed = False to managed = True
        self.add_command(
            ('dnf', 'install', '--allowerasing', '-y', '--exclude',
             'kernel-debug', 'python2-iml-agent-management'))
        self.assertEqual(agent_updates.update_profile({'managed': True}),
                         agent_result_ok)
        self.assertRanAllCommandsInOrder()

        # Go from managed = True to managed = False
        self.reset_command_capture()
        self.add_command(
            ('dnf', 'remove', '-y', 'python2-iml-agent-management'))
        self.assertEqual(agent_updates.update_profile({'managed': False}),
                         agent_result_ok)
        self.assertRanAllCommandsInOrder()

        # Go from managed = False to managed = False
        self.reset_command_capture()
        self.assertEqual(agent_updates.update_profile({'managed': False}),
                         agent_result_ok)
        self.assertRanAllCommandsInOrder()
Exemplo n.º 16
0
def reset_agent_config():
    from chroma_agent import DEFAULT_AGENT_CONFIG

    config.update("settings", "agent", DEFAULT_AGENT_CONFIG)
Exemplo n.º 17
0
def set_agent_config(key, val):
    agent_settings = config.get("settings", "agent")
    agent_settings[key] = val
    config.update("settings", "agent", agent_settings)
Exemplo n.º 18
0
def set_server_url(url):
    server_conf = dict(url=url)
    try:
        config.set('settings', 'server', server_conf)
    except ConfigKeyExistsError:
        config.update('settings', 'server', server_conf)
Exemplo n.º 19
0
def set_agent_config(key, val):
    agent_settings = config.get('settings', 'agent')
    agent_settings[key] = val
    config.update('settings', 'agent', agent_settings)
Exemplo n.º 20
0
def reset_agent_config():
    from chroma_agent import DEFAULT_AGENT_CONFIG
    config.update('settings', 'agent', DEFAULT_AGENT_CONFIG)