Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving detection of DVM state. #1601

Merged
merged 1 commit into from
Jun 5, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 50 additions & 12 deletions src/Robo/Inspector/Inspector.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ class Inspector implements BuilderAwareInterface, ConfigAwareInterface, LoggerAw
*/
protected $isMySqlAvailable = NULL;

/**
* @var array
*/
protected $drupalVmStatus = [];

/**
* The constructor.
*
Expand All @@ -56,6 +61,7 @@ public function __construct(Executor $executor) {
public function clearState() {
$this->isDrupalInstalled = NULL;
$this->isMySqlAvailable = NULL;
$this->drupalVmStatus = [];
}

/**
Expand Down Expand Up @@ -234,11 +240,10 @@ public function isDrupalVmConfigPresent() {
* TRUE if Drupal VM is initialized for the local machine.
*/
public function isDrupalVmLocallyInitialized() {
// We assume that if the local drush alias is ${project.machine_name.local},
// rather than self, then Drupal VM is being used locally.
$drush_local_alias = $this->getConfigValue('drush.aliases.local');
$expected_vm_alias = $this->getConfigValue('project.machine_name') . '.local';
$initialized = ($drush_local_alias == $expected_vm_alias) && file_exists($this->getConfigValue('repo.root') . '/box/config.yml');
$status = $this->getDrupalVmStatus();
$machine_name = $this->getConfigValue('project.machine_name');
$initialized = !empty($status[$machine_name])
&& file_exists($this->getConfigValue('repo.root') . '/box/config.yml');
$statement = $initialized ? "is" : "is not";
$this->logger->debug("Drupal VM $statement initialized.");

Expand All @@ -256,14 +261,11 @@ public function isDrupalVmBooted() {
return FALSE;
}

$result = $this->executor->execute("vagrant status")
->printOutput(FALSE)
->printMetadata(FALSE)
->interactive(FALSE)
->run();
$output = $result->getMessage();
$status = $this->getDrupalVmStatus();
$machine_name = $this->getConfigValue('project.machine_name');
$booted = !empty($status[$machine_name]['state'])
&& $status[$machine_name]['state'] == 'running';

$booted = strstr($output, "running");
$statement = $booted ? "is" : "is not";
$this->logger->debug("Drupal VM $statement booted.");

Expand Down Expand Up @@ -504,4 +506,40 @@ public function isSimpleSamlPhpInstalled() {
return $this->getConfig()->has('simplesamlphp') && $this->getConfigValue('simplesamlphp');
}

/**
* Gets the value of $this->drupalVmStatus. Sets it if empty.
*
* @return array
* An array of status data.
*/
protected function getDrupalVmStatus() {
if (empty($this->drupalVmStatus)) {
$this->setDrupalVmStatus();
}
return $this->drupalVmStatus;
}

/**
* Sets $this->drupalVmStatus by executing `vagrant status`.
*/
protected function setDrupalVmStatus() {
$result = $this->executor->execute("vagrant status --machine-readable")
->printOutput(FALSE)
->printMetadata(FALSE)
->interactive(FALSE)
->run();
$output = $result->getOutputData();
if (!$result->wasSuccessful() || !$output) {
return FALSE;
}
$lines = explode("\n", $output);
foreach ($lines as $line) {
if (count($line) < 4) {
continue;
}
list($timestamp, $target, $type, $data) = explode(',', $line);
$this->drupalVmStatus[$target][$type] = $data;
}
}

}