def set_profile(profile_json): profile = json.loads(profile_json) try: config.set('settings', 'profile', profile) except ConfigKeyExistsError: config.update('settings', 'profile', profile)
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()
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()
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)
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
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()
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
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
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"))
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 })
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, }, )
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()
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 }
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
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()
def reset_agent_config(): from chroma_agent import DEFAULT_AGENT_CONFIG config.update("settings", "agent", DEFAULT_AGENT_CONFIG)
def set_agent_config(key, val): agent_settings = config.get("settings", "agent") agent_settings[key] = val config.update("settings", "agent", agent_settings)
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)
def set_agent_config(key, val): agent_settings = config.get('settings', 'agent') agent_settings[key] = val config.update('settings', 'agent', agent_settings)
def reset_agent_config(): from chroma_agent import DEFAULT_AGENT_CONFIG config.update('settings', 'agent', DEFAULT_AGENT_CONFIG)