In Aegir's dev-services branch, we are dumping a bunch of configuration in site aliases. This works great locally, but they aren't passed on to remote servers. This patch merges in the alias's options.

Comments

greg.1.anderson’s picture

I have some reservations about this. Are remote-host and remote-user the only alias options that should not be propagated by drush_redispatch_get_option?

In drush-4.x, I think that we need to be able to clearly differentiate which alias items are options, and which items select the site. I think the proposed patch is probably okay for drush-3, but I'd like comments from Moshe and Adrian first. (Already implicitly approved by Adrian?)

greg.1.anderson’s picture

Status: Needs review » Needs work

Okay, here are my thoughts on this.

  1. There should be a function drush_sitealias_site_selection_keys that should return an array containing remote-host, remote-user, uri and root.
  2. drush_redispatch_get_option should call that function and unset any key thereby returned in $options.
  3. drush_redispatch_get_option should also unset command-specific and path-aliases.

Try out those changes; if it works for Aegir, then I think it would be ready to commit to the drush-3 branch too.

drumm’s picture

Status: Needs work » Needs review
StatusFileSize
new1.97 KB

Ok, updated patch attached.

I added 'name' to drush_sitealias_site_selection_keys().

I didn't add uri and root, since they are needed to find the remote Drupal installation. Unless I am missing some other way they are passed.

It is working for Aegir so far.

greg.1.anderson’s picture

Status: Needs review » Needs work

Every function that calls drush_redispatch_get_options should set uri and root. Sometimes they will be set to the same value as what is in the alias context, but in some instances they might not be, and it would be destructive to overwrite them. If you add 'uri' and 'root' to drush_sitealias_site_selection_keys, then I think the code looks pretty good.

Do let me know if that addition causes any problem for Aegir; it should still work, because 'uri' and 'root' should always be set. If they are not set because you are calling drush_redispatch_get_options directly from some Aegir function, then perhaps you should instead be calling drush_do_site_command with the alias record for "@self" (pass the result of drush_redispatch_get_options in as the 'data' argument).

drumm’s picture

StatusFileSize
new2.54 KB

Aha, I was hacking an alias into a call to drush_backend_invoke_args() and letting that sort it out by redispatch. drush_do_site_command() looks a lot cleaner. But that one only copies 'root' and 'uri', not the rest of the alias record. This is not a redispatch, it has a fresh set of args, data/options, and an alias determined by hostmaster.

I added code to copy over alias-specified options that are not overridden by $data in drush_do_site_command().

greg.1.anderson’s picture

Status: Needs work » Needs review

Code looks good, but I'm not going to be able to test it until later.

drumm’s picture

Unlike invoking from bash, drush_do_site_command() doesn't load the options into the 'alias' context. The options are passed as command line arguments. Is there another way commands should be invoked using aliases for more consistent behavior from the Drush API?

moshe weitzman’s picture

+++ includes/drush.inc	11 May 2010 21:31:10 -0000
@@ -1257,8 +1262,14 @@ function drush_do_command_redispatch($co
+  foreach (drush_sitealias_site_selection_keys() as $key) {
+    unset($options[$key]);
+  }

could be more terse with array_diff()?

otherwise, looks good. greg should test and commit when he is ready.

greg.1.anderson’s picture

Assigned: drumm » greg.1.anderson

Still catching up on backlog of stuff... feel free to assign issues to me, I'll try to get to these soon.

drumm’s picture

StatusFileSize
new2.49 KB

More-terse version as moshe suggested. array_diff_key() is PHP 5.1+ only.

greg.1.anderson’s picture

Drush will exit immediately if the php version is less than 5.2, so a php 5.1+ function is okay.

The above patch looks fine by inspection, but I still need to find time to sit down and test this.

greg.1.anderson’s picture

Status: Needs review » Needs work

#10 did not work. --root and --uri were not passed to the remote system, causing a bootstrap failure. I'm not sure why; looking at the code, it appears correct, but applying the patch broke remote commands, and removing it made them work again. I'm going to have to look at this more later, no time now.

From a -d run without the patch:

Running: ssh -o PasswordAuthentication=no 'root'@'reetstreet.com' 'drush    [command]
--d --uri='\''http://greenknowe.org'\'' --root='\''/srv/www/drupal'\''

From a -d run with the patch:

Running: ssh -o PasswordAuthentication=no 'root'@'reetstreet.com' 'drush    [command]
--project-type='\''live'\'' --d status --backend' [0.11 sec, 2.59 MB]
greg.1.anderson’s picture

Status: Needs work » Fixed
StatusFileSize
new2.62 KB

Committed the patch below after fixing the problem described in #12. 'root' and 'uri' from the site alias are applied to the options context, not the alias context, so I changed the site-specification stripping code to look like this:

  $alias_context = array_diff_key(drush_get_context('alias'), array_flip(drush_sitealias_site_selection_keys()));
  $options = array_merge($alias_context, drush_get_context('options'));

This insures that items that are applied to the options context (e.g. 'root' and 'uri') are still passed on, because if they're in 'options', they're needed for identification in the remote dispatch.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.