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.

Update the create_job interface appropriately.

Signed-off-by: Nishanth Aravamudan <[email protected]>

---
I have not tested the cli submission of jobs yet. I *think* it should
work similar to the regular host. But I need to look into it still.


diff --git a/frontend/afe/rpc_interface.py b/frontend/afe/rpc_interface.py
index e316af9..8308e1e 100644
--- a/frontend/afe/rpc_interface.py
+++ b/frontend/afe/rpc_interface.py
@@ -264,6 +264,50 @@ def get_num_hosts(multiple_labels=(), 
exclude_only_if_needed_labels=False,
     return hosts.count()
 
 
+def get_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)
+
+    error_encountered = True
+    profile_dicts = []
+    if install_server is not None:
+        profiles = install_server.get_item_names('profile')
+
+        if len(profiles) < 1:
+            msg = 'No profiles defined on install server'
+            rpc_logger = logging.getLogger('rpc_logger')
+            rpc_logger.info(msg, host_dict['hostname'])
+
+        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.
+    """
+    profiles = install_server.get_item_names('profile')
+
+    # Add the do not install entry
+    return len(profiles) + 1
+
 # tests
 
 def add_test(name, test_type, path, author=None, dependencies=None,
@@ -449,7 +493,7 @@ def create_parameterized_job(name, priority, test, 
parameters, kernel=None,
                              profiler_parameters=None,
                              use_container=False, profile_only=None,
                              upload_kernel_config=False, hosts=(),
-                             meta_hosts=(), one_time_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 +576,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_utils.py b/frontend/afe/rpc_utils.py
index ee3a0b0..730156e 100644
--- a/frontend/afe/rpc_utils.py
+++ b/frontend/afe/rpc_utils.py
@@ -458,10 +458,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 +511,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 +640,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 +755,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/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

_______________________________________________
Autotest-kernel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/autotest-kernel

Reply via email to