Use an RPC call, just like for specific hosts, for finding all possible profiles. We let the user shoot themselves in the foot (that is, they might select a profile that doesn't apply to that server), but that's the nature of selecting by label -- unless the label is a platform, we won't be able to do the lookup anyways in the install server.
Changes from v1: * Fix up various parameters in the RPC interfaces to be lists rather than tuples. * Fix-up unittests to pass in lists rather than tuples. * Fix logging exception. * Fix monitor_db.py call of create_new_job. * Fix indentation issue. * Refactor code so install server is available for get_num_profiles(). Signed-off-by: Nishanth Aravamudan <[email protected]> diff --git a/client/tests b/client/tests index 247d18a..f418fd2 160000 --- a/client/tests +++ b/client/tests @@ -1 +1 @@ -Subproject commit 247d18a547fa4138124885e39000b2163cca8d7e +Subproject commit f418fd2997bfbe0bb4e6ab40aec71d1b7f2a6fde diff --git a/frontend/afe/resources.py b/frontend/afe/resources.py index 3c5db7e..30cf25e 100644 --- a/frontend/afe/resources.py +++ b/frontend/afe/resources.py @@ -661,7 +661,8 @@ class Job(resource_lib.InstanceEntry): @classmethod def create_instance(cls, input_dict, containing_collection): owner = input_dict.get('owner') - profiles = input_dict.get('profiles', None) + profiles = input_dict.get('profiles', []) + metahost_profiles = input_dict.get('metahost_profiles', []) if not owner: owner = models.User.current_user().login @@ -718,6 +719,7 @@ class Job(resource_lib.InstanceEntry): host_objects=host_objects, profiles=profiles, metahost_objects=metahost_label_objects, + metahost_profiles=metahost_profiles, atomic_group=atomic_group) return models.Job.objects.get(id=job_id) diff --git a/frontend/afe/rpc_interface.py b/frontend/afe/rpc_interface.py index e316af9..beb7746 100644 --- a/frontend/afe/rpc_interface.py +++ b/frontend/afe/rpc_interface.py @@ -264,6 +264,67 @@ def get_num_hosts(multiple_labels=(), exclude_only_if_needed_labels=False, return hosts.count() +def get_install_server_profiles(): + install_server = None + install_server_info = get_install_server_info() + install_server_type = install_server_info.get('type', None) + install_server_url = install_server_info.get('xmlrpc_url', None) + + if install_server_type == 'cobbler' and install_server_url: + install_server = xmlrpclib.ServerProxy(install_server_url) + + if install_server is None: + return None + + return install_server.get_item_names('profile') + + +def get_profiles(): + error_encountered = True + profile_dicts = [] + profiles = get_install_server_profiles() + if profiles is not None: + if len(profiles) < 1: + msg = 'No profiles defined on install server' + rpc_logger = logging.getLogger('rpc_logger') + rpc_logger.info(msg) + + else: + error_encountered = False + # not sorted + profiles.sort() + profile_dicts.append(dict(name="Do_not_install")) + for profile in profiles: + profile_dicts.append(dict(name=profile)) + + if error_encountered: + profile_dicts.append(dict(name="N/A")) + + return rpc_utils.prepare_for_serialization(profile_dicts) + + +def get_num_profiles(): + """ + Same parameters as get_profiles(). + + @returns The number of defined profiles. + """ + error_encountered = True + profiles = get_install_server_profiles() + if profiles is not None: + if len(profiles) < 1: + # 'N/A' + return 1 + + else: + # include 'Do_not_install' + return len(profiles) + 1 + + if error_encountered: + # 'N/A' + return 1 + + # tests def add_test(name, test_type, path, author=None, dependencies=None, @@ -445,11 +506,11 @@ def generate_control_file(tests=(), kernel=None, label=None, profilers=(), def create_parameterized_job(name, priority, test, parameters, kernel=None, - label=None, profiles=(), profilers=(), + label=None, profiles=[], profilers=(), profiler_parameters=None, use_container=False, profile_only=None, - upload_kernel_config=False, hosts=(), - meta_hosts=(), one_time_hosts=(), + upload_kernel_config=False, hosts=[], + meta_hosts=[], meta_host_profiles=[], one_time_hosts=[], atomic_group_name=None, synch_count=None, is_template=False, timeout=None, max_runtime_hrs=None, run_verify=True, @@ -532,10 +593,10 @@ def create_parameterized_job(name, priority, test, parameters, kernel=None, def create_job(name, priority, control_file, control_type, - hosts=(), profiles=(), meta_hosts=(), one_time_hosts=(), - atomic_group_name=None, synch_count=None, is_template=False, - timeout=None, max_runtime_hrs=None, run_verify=True, - email_list='', dependencies=(), reboot_before=None, + hosts=[], profiles=[], meta_hosts=[], meta_host_profiles=[], + one_time_hosts=[], atomic_group_name=None, synch_count=None, + is_template=False, timeout=None, max_runtime_hrs=None, + run_verify=True, email_list='', dependencies=(), reboot_before=None, reboot_after=None, parse_failed_repair=None, hostless=False, keyvals=None, drone_set=None): """\ diff --git a/frontend/afe/rpc_interface_unittest.py b/frontend/afe/rpc_interface_unittest.py index f0f9e31..3ace0dd 100755 --- a/frontend/afe/rpc_interface_unittest.py +++ b/frontend/afe/rpc_interface_unittest.py @@ -339,7 +339,7 @@ class RpcInterfaceTest(unittest.TestCase, name='job', priority=models.Job.Priority.MEDIUM, test='test', parameters=job_parameters, kernel=kernels, label='label1', profilers=profilers, profiler_parameters=profiler_parameters, - profile_only=False, hosts=('host1',), profiles=('rhel6',)) + profile_only=False, hosts=['host1',], profiles=['rhel6',]) parameterized_job = models.Job.smart_get(job_id).parameterized_job self.assertEqual(parameterized_job.test, test) diff --git a/frontend/afe/rpc_utils.py b/frontend/afe/rpc_utils.py index ee3a0b0..ba1849a 100644 --- a/frontend/afe/rpc_utils.py +++ b/frontend/afe/rpc_utils.py @@ -397,6 +397,7 @@ def get_job_info(job, preserve_metahosts=False, queue_entry_filter_data=None): profiles = [] one_time_hosts = [] meta_hosts = [] + meta_host_profiles = [] atomic_group = None hostless = False @@ -417,6 +418,7 @@ def get_job_info(job, preserve_metahosts=False, queue_entry_filter_data=None): profiles.append(queue_entry.profile) elif queue_entry.meta_host: meta_hosts.append(queue_entry.meta_host) + meta_host_profiles.append(queue_entry.profile) else: hostless = True @@ -436,6 +438,7 @@ def get_job_info(job, preserve_metahosts=False, queue_entry_filter_data=None): hosts=hosts, profiles=profiles, meta_hosts=meta_hosts, + meta_host_profiles=meta_host_profiles, meta_host_counts=meta_host_counts, one_time_hosts=one_time_hosts, atomic_group=atomic_group, @@ -458,10 +461,11 @@ def check_for_duplicate_hosts(host_objects): def create_new_job(owner, options, host_objects, profiles, metahost_objects, - atomic_group=None): + metahost_profiles, atomic_group=None): labels_by_name = dict((label.name, label) for label in models.Label.objects.all()) all_host_objects = host_objects + metahost_objects + all_profiles = profiles + metahost_profiles metahost_counts = _get_metahost_counts(metahost_objects) dependencies = options.get('dependencies', []) synch_count = options.get('synch_count') @@ -510,7 +514,7 @@ def create_new_job(owner, options, host_objects, profiles, metahost_objects, job = models.Job.create(owner=owner, options=options, hosts=all_host_objects) - job.queue(all_host_objects, profiles=profiles, atomic_group=atomic_group, + job.queue(all_host_objects, profiles=all_profiles, atomic_group=atomic_group, is_template=options.get('is_template', False)) return job.id @@ -639,8 +643,8 @@ def get_create_job_common_args(local_args): def create_job_common(name, priority, control_type, control_file=None, - hosts=(), profiles=(), meta_hosts=(), one_time_hosts=(), - atomic_group_name=None, synch_count=None, + hosts=[], profiles=[], meta_hosts=[], meta_host_profiles=[], + one_time_hosts=[], atomic_group_name=None, synch_count=None, is_template=False, timeout=None, max_runtime_hrs=None, run_verify=True, email_list='', dependencies=(), reboot_before=None, reboot_after=None, @@ -754,4 +758,5 @@ def create_job_common(name, priority, control_type, control_file=None, host_objects=host_objects, profiles=profiles, metahost_objects=metahost_objects, + metahost_profiles=meta_host_profiles, atomic_group=atomic_group) diff --git a/frontend/client/src/autotest/afe/HostSelector.java b/frontend/client/src/autotest/afe/HostSelector.java index 413fc1b..e088b4e 100644 --- a/frontend/client/src/autotest/afe/HostSelector.java +++ b/frontend/client/src/autotest/afe/HostSelector.java @@ -23,6 +23,7 @@ import com.google.gwt.user.client.ui.Anchor; import com.google.gwt.user.client.ui.HasText; import com.google.gwt.user.client.ui.HasValue; import com.google.gwt.user.client.ui.Widget; +import com.google.gwt.user.client.Window; import java.util.ArrayList; import java.util.Collection; @@ -49,6 +50,7 @@ public class HostSelector implements ClickHandler { public List<String> hosts = new ArrayList<String>(); public List<String> profiles = new ArrayList<String>(); public List<String> metaHosts = new ArrayList<String>(); + public List<String> metaHostProfiles = new ArrayList<String>(); public List<String> oneTimeHosts = new ArrayList<String>(); } @@ -70,6 +72,7 @@ public class HostSelector implements ClickHandler { private Display display; private HostDataSource hostDataSource = new HostDataSource(); + private ProfileDataSource profileDataSource = new ProfileDataSource(); // availableTable needs its own data source private HostTable availableTable = new HostTable(new HostDataSource()); private HostTableDecorator availableDecorator = @@ -260,6 +263,7 @@ public class HostSelector implements ClickHandler { JSONObject oneTimeObject = new JSONObject(); oneTimeObject.put("hostname", new JSONString(hostname)); oneTimeObject.put("platform", new JSONString(ONE_TIME)); + // need to add profiles here too, I think selectRow(oneTimeObject); } @@ -282,18 +286,42 @@ public class HostSelector implements ClickHandler { } addMetaHosts(label, number); - selectionRefresh(); } - public void addMetaHosts(String label, String number) { + public void addMetaHosts(final String label, final String number) { + JSONObject params = new JSONObject(); + profileDataSource.query(params, new DefaultDataCallback () { + @Override + public void onQueryReady(Query query) { + query.getPage(null, null, null, this); + } + + @Override + public void handlePage(List<JSONObject> data) { + processAddByLabel(label, number, data); + } + }); + } + + private void processAddByLabel(final String label, final String number, List<JSONObject> data) { JSONObject metaObject = new JSONObject(); + JSONArray profiles = new JSONArray(); + int i = 0; metaObject.put("hostname", new JSONString(META_PREFIX + number)); metaObject.put("platform", new JSONString(label)); metaObject.put("other_labels", new JSONString("")); metaObject.put("status", new JSONString("")); metaObject.put("locked_text", new JSONString("")); metaObject.put("id", new JSONNumber(--META_INDEX)); + for (JSONObject profile : data) { + String p = profile.get("name").toString(); + // JSON seems to insert extra quotes + profiles.set(i, new JSONString(p.substring(1, p.length()-1))); + i++; + } + metaObject.put("profiles", profiles); selectRow(metaObject); + selectionRefresh(); } private void selectRow(JSONObject row) { @@ -355,8 +383,10 @@ public class HostSelector implements ClickHandler { if (isMetaEntry(row)) { int count = getMetaNumber(row); String platform = row.get("platform").isString().stringValue(); + String profile = getProfile(row); for(int counter = 0; counter < count; counter++) { selection.metaHosts.add(platform); + selection.metaHostProfiles.add(profile); } } else { diff --git a/frontend/client/src/autotest/afe/ProfileDataSource.java b/frontend/client/src/autotest/afe/ProfileDataSource.java new file mode 100644 index 0000000..96d9a7d --- /dev/null +++ b/frontend/client/src/autotest/afe/ProfileDataSource.java @@ -0,0 +1,9 @@ +package autotest.afe; + +import autotest.common.table.RpcDataSource; + +public class ProfileDataSource extends RpcDataSource { + public ProfileDataSource() { + super("get_profiles", "get_num_profiles"); + } +} diff --git a/frontend/client/src/autotest/afe/create/CreateJobViewPresenter.java b/frontend/client/src/autotest/afe/create/CreateJobViewPresenter.java index 822832a..29a17a7 100644 --- a/frontend/client/src/autotest/afe/create/CreateJobViewPresenter.java +++ b/frontend/client/src/autotest/afe/create/CreateJobViewPresenter.java @@ -593,6 +593,7 @@ public class CreateJobViewPresenter implements TestSelectorListener { args.put("hosts", Utils.stringsToJSON(hosts.hosts)); args.put("profiles", Utils.stringsToJSON(hosts.profiles)); args.put("meta_hosts", Utils.stringsToJSON(hosts.metaHosts)); + args.put("meta_host_profiles", Utils.stringsToJSON(hosts.metaHostProfiles)); args.put("one_time_hosts", Utils.stringsToJSON(hosts.oneTimeHosts)); diff --git a/scheduler/monitor_db.py b/scheduler/monitor_db.py index 94b57e5..68d2b1a 100644 --- a/scheduler/monitor_db.py +++ b/scheduler/monitor_db.py @@ -825,6 +825,7 @@ class Dispatcher(object): profiles = info['profiles'] one_time_hosts = info['one_time_hosts'] metahost_objects = info['meta_hosts'] + metahost_profiles = info['meta_host_profiles'] atomic_group = info['atomic_group'] for host in one_time_hosts or []: @@ -837,6 +838,7 @@ class Dispatcher(object): host_objects=host_objects, profiles=profiles, metahost_objects=metahost_objects, + metahost_profiles=metahost_profiles, atomic_group=atomic_group) except Exception, ex: diff --git a/server/frontend.py b/server/frontend.py index 8f3b3c6..fbef6ed 100644 --- a/server/frontend.py +++ b/server/frontend.py @@ -177,6 +177,10 @@ class AFE(RpcClient): return [Host(self, h) for h in hosts] + def get_profiles(self): + return self.run('get_profiles') + + def get_hostnames(self, status=None, label=None, **dargs): """Like get_hosts() but returns hostnames instead of Host objects.""" # This implementation can be replaced with a more efficient one diff --git a/server/tests b/server/tests index e385a55..612c1bc 160000 --- a/server/tests +++ b/server/tests @@ -1 +1 @@ -Subproject commit e385a556b96ab9359d32ff4b281e667a4061b6ed +Subproject commit 612c1bcda14d95afcf9745e5ecc3fa18f085a302 _______________________________________________ Autotest-kernel mailing list [email protected] https://www.redhat.com/mailman/listinfo/autotest-kernel
