Blame view
sources/3rdparty/rackspace/php-opencloud/tests/OpenCloud/Smoke/Unit/AbstractUnit.php
4.33 KB
|
6d9380f96
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
<?php
/**
* PHP OpenCloud library.
*
* @copyright 2014 Rackspace Hosting, Inc. See LICENSE for information.
* @license https://www.apache.org/licenses/LICENSE-2.0
* @author Jamie Hannaford <jamie.hannaford@rackspace.com>
*/
namespace OpenCloud\Smoke\Unit;
use OpenCloud\OpenStack;
use OpenCloud\Common\Service\AbstractService;
use OpenCloud\Smoke\Enum;
use OpenCloud\Smoke\Step;
use OpenCloud\Smoke\Utils;
/**
* Description of AbstractUnit
*
* @link
*/
abstract class AbstractUnit
{
/**
* The credentials cache filename.
*
* @var string
*/
private $credentialsCacheFile;
/**
* The connection object which everything routes through.
*
* @var OpenCloud\OpenStack
*/
protected $connection;
/**
* The particular service that each unit uses.
*
* @var OpenCloud\Common\Service
*/
protected $service;
protected $currentStep;
protected $currentSubStep;
protected $includedUnits;
/**
* Factory method for instantiating the unit object, and executing its
* main algorithm.
*
* @return UnitInterface
*/
public static function factory(OpenStack $connection, array $includedUnits)
{
$unit = new static();
$unit->setConnection($connection)
->setIncludedUnits($includedUnits);
if (!$service = $unit->setupService()) {
return false;
}
$unit->setService($service);
// Run execution...
$unit->main();
// Clean stuff up if necessary...
$unit->teardown();
return $unit;
}
public function setConnection(OpenStack $connection)
{
$this->connection = $connection;
return $this;
}
public function getConnection()
{
return $this->connection;
}
public function setService(AbstractService $service)
{
$this->service = $service;
return $this;
}
public function getService()
{
return $this->service;
}
public function setIncludedUnits(array $includedUnits)
{
$this->includedUnits = $includedUnits;
return $this;
}
public function getIncludedUnits()
{
return $this->includedUnits;
}
public function getWaiterCallback()
{
return function($object) {
if (!empty($object->error)) {
var_dump($object->error); die;
} else {
$this->stepInfoDotter(
"Waiting on %s/%-12s %4s%%",
$object->name(),
$object->status(),
isset($object->progress) ? $object->progress : 0
);
}
};
}
public function shouldDelete($string)
{
return preg_match('#(?:S|s)moke(?:T|t)est#', $string) !== false;
//return stristr($string, Enum::GLOBAL_PREFIX) !== false;
}
public function prepend($string)
{
return Enum::GLOBAL_PREFIX . $string;
}
public function step()
{
$string = Utils::convertArgsToString(func_get_args());
$count = (!$this->currentStep) ? 1 : $this->currentStep->getCount() + 1;
$this->currentStep = Step::factory($string, $count);
}
public function subStep()
{
$string = Utils::convertArgsToString(func_get_args());
return $this->createSubStep($string);
}
public function stepInfo()
{
$string = Utils::convertArgsToString(func_get_args());
return $this->createSubStep($string, Step::TYPE_SPACER);
}
public function stepInfoDotter()
{
$string = Utils::convertArgsToString(func_get_args());
return $this->createSubStep($string, Step::TYPE_DOTTER);
}
public function createSubStep($string, $outputType = null)
{
// Set basic properties
$step = $this->currentStep->subStep($string)
->setOutputType($outputType);
// If we have a preceding sub-step, we need to make sure our new one
// is properly incremented
if ($this->currentSubStep) {
$step->setCount($this->currentSubStep->getCount() + 1);
}
$this->currentSubStep = $step;
return $step->output();
}
}
|