/** * remove data using a dot.notation.path * * @param string $path * the dot.notation.path to use to navigate * * @return void */ public function unsetData($path) { return $this->config->unsetData($path); }
public function mergeSystemUnderTestConfig($sutConfig) { // do we have anything to merge? if (!$sutConfig->hasData('roles')) { // nothing to merge return; } // get the list of roles $sutRoles = $sutConfig->getData('roles'); // get our config $envConfig = $this->getConfig(); foreach ($sutRoles as $sutRole) { foreach ($envConfig->groups as $envDetails) { foreach ($envDetails->details->machines as $machine) { if (in_array($sutRole->role, $machine->roles) || in_array('*', $machine->roles)) { if (!isset($machine->params)) { $machine->params = new BaseObject(); } else { if (!$machine->params instanceof BaseObject) { $tmp = new BaseObject(); $tmp->mergeFrom($machine->params); $machine->params = $tmp; } } $machine->params->mergeFrom($sutRole->params); } } } } }
/** * load test users from the given filename * * NOTES: * * - Storyplayer calls this for you when you use the --users switch * * - it is safe to call this yourself from a story if you want to load * additional users for any reason. however, Storyplayer will not manage * saving these users for you - you WILL have to do that yourself * * @param string $filename * the JSON file to load users from * @return \DataSift\Stone\ObjectLib\BaseObject */ public function loadUsersFromFile($filename) { // what are we doing? $log = usingLog()->startAction("load test users from '{$filename}'"); // load the file $raw = @file_get_contents($filename); if (!$raw || empty($raw)) { throw new E5xx_ActionFailed(__METHOD__, "cannot open file '{$filename}' or file is empty"); } $plainUsers = json_decode($raw); if ($plainUsers === null) { throw new E5xx_ActionFailed(__METHOD__, "file '{$filename}' contains invalid JSON"); } if (!is_object($plainUsers)) { throw new E5xx_ActionFailed(__METHOD__, "file '{$filename}' must contain a JSON object"); } // merge these in with any users we have already loaded $users = new BaseObject(); $users->mergeFrom($plainUsers); // remember what we've loaded $this->st->setTestUsers($users); // all done $count = count(get_object_vars($users)); $log->endAction("loaded {$count} test user(s)"); return $users; }
/** * add some extra provisioning parameters to any that have already been * defined * * this is mostly used when we merge parameters across from the * SystemUnderTest config * * @param mixed $extraParams * the extra parameters to merge in * * @return TestEnvironment_HostDefinition */ public function addProvisioningParams($extraParams) { // let's get them merged in $this->provisioningParams->mergeFrom($extraParams); // fluent interface support return $this; }
/** * * @return \DataSift\Stone\ObjectLib\BaseObject */ public function loadRuntimeConfig(Output $output) { // where is the config file? $configDir = $this->getConfigDir(); $filename = $configDir . "/" . self::RUNTIME_FILENAME; // does the file exist? if (!is_file($filename)) { return new BaseObject(); } // at this point, we should be able to load the config $raw = @file_get_contents($filename); if (FALSE === $raw) { $output->logCliError("unable to read config file '{$filename}'; permissions error?"); exit(1); } // the config file may be empty if (strlen(rtrim($raw)) === 0) { return new BaseObject(); } $config = @json_decode($raw); if (NULL === $config) { $output->logCliError("unable to parse JSON in config file '{$filename}'"); exit(1); } // we need to convert the loaded config into our more powerful config // (at least for now) $enhancedConfig = new BaseObject(); $enhancedConfig->mergeFrom($config); // all done return $enhancedConfig; }
public function provisionHosts(ProvisioningDefinition $hosts, $provConfig) { // what are we doing? $log = usingLog()->startAction("use dsbuild to provision host(s)"); // the params file that we are going to output $dsbuildParams = new BaseObject(); // build up the list of settings to write out foreach ($hosts as $hostId => $hostProps) { // what is the host's IP address? $ipAddress = fromHost($hostId)->getIpAddress(); $propName = $hostId . '_ipv4Address'; $dsbuildParams->{$propName} = $ipAddress; if (isset($hostProps->params)) { $dsbuildParams->mergeFrom($hostProps->params); } } // add in all the config settings that we know about $dsbuildParams->storyplayer_ipv4Address = fromConfig()->get('storyplayer.ipAddress'); $dsbuildParams->mergeFrom($this->flattenData($this->st->getActiveConfig()->getData(''))); // write them out $this->writeDsbuildParamsShellFile((array) $dsbuildParams); $this->writeDsbuildParamsYamlFile((array) $dsbuildParams); // at this point, we are ready to attempt provisioning // // provision each host in the order that they're listed foreach ($hosts as $hostId => $hostProps) { // which dsbuildfile are we going to run? $hostDir = fromHost($hostId)->getLocalFolder(); $dsbuildFilename = $this->getDsbuildFilename($hostDir, $provConfig, $hostId); if ($dsbuildFilename === null) { // there is no dsbuildfile at all to run $log->endAction("cannot find dsbuildfile to run :("); throw new E5xx_ActionFailed(__METHOD__, "no dsbuildfile to run"); } // at this point, we are ready to provision $commandRunner = new CommandRunner(); // copy the dsbuildparams files to the target machine using scp // NOTE: the "vagrant rsync" command seems not working with some Vagrant provisioners (e.g. OpenStack) $command = 'scp' . ' ' . $dsbuildParams->{'hosts_' . $hostId . '_scpOptions_0'} . ' ' . $dsbuildParams->{'hosts_' . $hostId . '_scpOptions_1'} . ' dsbuildparams.*' . ' ' . $dsbuildParams->{'hosts_' . $hostId . '_sshUsername'} . '@' . $dsbuildParams->{'hosts_' . $hostId . '_ipAddress'} . ':/vagrant/'; $result = $commandRunner->runSilently($command); if (!$result->didCommandSucceed()) { // try to rsync folders in case of scp fail $command = 'vagrant rsync ' . $hostId; $commandRunner->runSilently($command); } // provision $command = 'sudo bash /vagrant/' . $dsbuildFilename; $result = usingHost($hostId)->runCommand($command); // what happened? if (!$result->didCommandSucceed()) { throw new E5xx_ActionFailed(__METHOD__, "provisioning failed"); } } // all done $log->endAction(); }