Increase controll over content of deployment config
Allow caller to provide "images" branch of deployement config structure. Also provide called API to make "correct"/"default" images branch. Till now setup method of environment object silentlry override "images" branch. Change-Id: I1bdb0f91c7bf83e3c888650b2f8917dde80dea42
This commit is contained in:
parent
5970e9dbb5
commit
34740f5411
|
@ -13,6 +13,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import collections
|
||||
import errno
|
||||
import os
|
||||
import shutil
|
||||
|
@ -72,7 +73,7 @@ PXELINUX_PATH = (
|
|||
class Environment(object):
|
||||
_loaded_config = object() # to fail comparison with None
|
||||
|
||||
deploy_driver = None
|
||||
deploy_driver = 'swift'
|
||||
node = None
|
||||
network = None
|
||||
webserver = None
|
||||
|
@ -108,10 +109,9 @@ class Environment(object):
|
|||
self._check_rsync()
|
||||
self._setup_pxe()
|
||||
|
||||
def setup(self, node_template, deploy_config, tenant_image=None,
|
||||
deploy_driver='swift'):
|
||||
def setup(self, node_template, deploy_config):
|
||||
"""Per-test setup"""
|
||||
self.deploy_driver = deploy_driver
|
||||
|
||||
ssh_key_path = os.path.join(CONF.image_build_dir, CONF.ramdisk_key)
|
||||
self.node = node.Node(
|
||||
self.jinja_env, node_template, self.network.name, ssh_key_path)
|
||||
|
@ -121,7 +121,6 @@ class Environment(object):
|
|||
self.add_pxe_config_for_current_node()
|
||||
self.network.add_node(self.node)
|
||||
|
||||
deploy_config = self._set_tenant_image(deploy_config, tenant_image)
|
||||
path = self._save_provision_json_for_node(deploy_config)
|
||||
|
||||
self.node.start()
|
||||
|
@ -149,8 +148,7 @@ class Environment(object):
|
|||
self.network.kill()
|
||||
self._delete_workdir()
|
||||
|
||||
def update_deploy_config(self, deploy_config, tenant_image=None):
|
||||
deploy_config = self._set_tenant_image(deploy_config, tenant_image)
|
||||
def update_deploy_config(self, deploy_config):
|
||||
path = self._save_provision_json_for_node(deploy_config)
|
||||
self.node.put_file(path, '/tmp/provision.json')
|
||||
|
||||
|
@ -220,42 +218,39 @@ class Environment(object):
|
|||
cmd = ['ramdisk-stub-webserver', self.network.address, str(port)]
|
||||
self.webserver = subprocess.Popen(cmd, shell=False)
|
||||
|
||||
def _set_tenant_image(self, deploy_config, image_name=None):
|
||||
if isinstance(image_name, basestring):
|
||||
images = self._set_single_tenant_image(image_name)
|
||||
elif isinstance(image_name, dict):
|
||||
images = self._set_multiple_tenant_image(image_name)
|
||||
def patch_config_images(self, deploy_config, payload=None):
|
||||
if isinstance(payload, basestring):
|
||||
images = [self._make_image_config_record(payload)]
|
||||
elif isinstance(payload, collections.Mapping):
|
||||
images = self._set_multiple_tenant_image(payload)
|
||||
elif payload is None:
|
||||
record = self._make_image_config_record('FAKE')
|
||||
record['image_pull_url'] = 'http://{0}:{1}/fake'.format(
|
||||
self.network.address, CONF.stub_webserver_port),
|
||||
images = [record]
|
||||
else:
|
||||
images = self._set_image_stub()
|
||||
raise TypeError('Invalid "payload" value: {!r}'.format(payload))
|
||||
|
||||
deploy_config['images'] = images
|
||||
return deploy_config
|
||||
|
||||
def _set_single_tenant_image(self, image_name=None, os_id=None, boot=True):
|
||||
return [{
|
||||
"name": os_id or image_name,
|
||||
def _make_image_config_record(self, name, boot=True):
|
||||
return {
|
||||
"name": name,
|
||||
"boot": boot,
|
||||
"target": '/',
|
||||
"image_pull_url": self.get_url_for_image(
|
||||
image_name, self.deploy_driver),
|
||||
}]
|
||||
|
||||
def _set_image_stub(self):
|
||||
return [{
|
||||
"name": "FAKE",
|
||||
"boot": True,
|
||||
"target": '/',
|
||||
"image_pull_url": "http://{0}:{1}/fake".format(
|
||||
self.network.address, CONF.stub_webserver_port),
|
||||
}]
|
||||
name, self.deploy_driver),
|
||||
}
|
||||
|
||||
def _set_multiple_tenant_image(self, image_names):
|
||||
images = []
|
||||
for index, element in enumerate(image_names.items()):
|
||||
os_id, image_name = element
|
||||
boot = True if index == 0 else False
|
||||
image_data = self._set_single_tenant_image(image_name, os_id, boot)
|
||||
images.append(image_data[0])
|
||||
os_id, name = element
|
||||
if not name:
|
||||
name = os_id
|
||||
record = self._make_image_config_record(name, boot=index == 0)
|
||||
images.append(record)
|
||||
return images
|
||||
|
||||
def get_url_for_image(self, image_name, source_type):
|
||||
|
@ -266,10 +261,6 @@ class Environment(object):
|
|||
else:
|
||||
raise exception.UnknownDeployDriver()
|
||||
|
||||
def get_url_for_stub_image(self):
|
||||
return "http://{0}:{1}/fake".format(self.network.address,
|
||||
CONF.stub_webserver_port)
|
||||
|
||||
def _get_swift_tenant_image_url(self, image_name):
|
||||
return (
|
||||
'http://{0}:{1}/tenant_images/{2}'.format(
|
||||
|
|
Loading…
Reference in New Issue