]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
provision/downburst: add machine customization 1548/head
authorKyr Shatskyy <kyrylo.shatskyy@suse.com>
Fri, 21 Aug 2020 11:42:31 +0000 (13:42 +0200)
committerKyr Shatskyy <kyrylo.shatskyy@suse.com>
Mon, 31 Aug 2020 21:22:32 +0000 (23:22 +0200)
Signed-off-by: Kyr Shatskyy <kyrylo.shatskyy@suse.com>
teuthology/provision/downburst.py

index 28c36bfd0e020d460626c68866b0eda012d01ef5..90feea239c7aa71f13e888c5b22de2cbf035799b 100644 (file)
@@ -8,6 +8,7 @@ import yaml
 from teuthology.config import config
 from teuthology.contextutil import safe_while
 from teuthology.misc import decanonicalize_hostname
+from teuthology.misc import deep_merge
 from teuthology.lock import query
 
 log = logging.getLogger(__name__)
@@ -20,7 +21,11 @@ def downburst_executable():
     Return '' if no executable downburst is found.
     """
     if config.downburst:
-        return config.downburst
+        if isinstance(config.downburst, dict):
+            if 'path' in config.downburst:
+                return config.downburst['path']
+        else:
+            return config.downburst
     path = os.environ.get('PATH', None)
     if path:
         for p in os.environ.get('PATH', '').split(os.pathsep):
@@ -37,6 +42,17 @@ def downburst_executable():
     return ''
 
 
+def downburst_environment():
+    env = dict()
+    discover_url = os.environ.get('DOWNBURST_DISCOVER_URL')
+    if config.downburst and not discover_url:
+        if isinstance(config.downburst, dict):
+            discover_url = config.downburst.get('discover_url')
+    if discover_url:
+        env['DOWNBURST_DISCOVER_URL'] = discover_url
+    return env
+
+
 class Downburst(object):
     """
     A class that provides methods for creating and destroying virtual machine
@@ -55,6 +71,7 @@ class Downburst(object):
         self.logfile = logfile
         self.host = decanonicalize_hostname(self.status['vm_host']['name'])
         self.executable = downburst_executable()
+        self.environment = downburst_environment()
 
     def create(self):
         """
@@ -120,6 +137,7 @@ class Downburst(object):
         ))
         log.debug(args)
         proc = subprocess.Popen(args, universal_newlines=True,
+                                env=self.environment,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
         out, err = proc.communicate()
@@ -166,22 +184,35 @@ class Downburst(object):
         os_version = self.os_version.lower()
 
         mac_address = self.status['mac_address']
-
-        cpus = int(os.environ.get('DOWNBURST_CPUS', 1))
-        ram_size = os.environ.get('DOWNBURST_RAM_SIZE', '3.8G')
-        disk_size = os.environ.get('DOWNBURST_DISK_SIZE', '100G')
-        extra_disk_size = os.environ.get('DOWNBURST_EXTRA_DISK_SIZE', '100G')
-        extra_disk_number = int(os.environ.get('DOWNBURST_EXTRA_DISK_NUMBER', 4))
+        defaults = dict(
+            downburst=dict(
+                machine=dict(
+                    disk=os.environ.get('DOWNBURST_DISK_SIZE', '100G'),
+                    ram=os.environ.get('DOWNBURST_RAM_SIZE', '3.8G'),
+                    cpus=int(os.environ.get('DOWNBURST_CPUS', 1)),
+                    volumes=dict(
+                        count=int(os.environ.get('DOWNBURST_EXTRA_DISK_NUMBER', 4)),
+                        size=os.environ.get('DOWNBURST_EXTRA_DISK_SIZE', '100G'),
+                    ),
+                ),
+            )
+        )
+        downburst_config = defaults['downburst']
+        if config.downburst and isinstance(config.downburst, dict):
+            deep_merge(downburst_config, config.downburst)
+        log.debug('downburst_config: %s', downburst_config)
+        machine = downburst_config['machine']
+        log.debug('Using machine config: %s', machine)
         file_info = {
-            'disk-size': disk_size,
-            'ram': ram_size,
-            'cpus': cpus,
+            'disk-size': machine['disk'],
+            'ram': machine['ram'],
+            'cpus': machine['cpus'],
             'networks': [
                 {'source': 'front', 'mac': mac_address}],
             'distro': os_type,
             'distroversion': self.os_version,
-            'additional-disks': extra_disk_number,
-            'additional-disks-size': extra_disk_size,
+            'additional-disks': machine['volumes']['count'],
+            'additional-disks-size': machine['volumes']['size'],
             'arch': 'x86_64',
         }
         fqdn = self.name.split('@')[1]
@@ -274,12 +305,15 @@ def get_distro_from_downburst():
                      'opensuse': ['12.3', '15.1', '15.2'],
                      'debian': ['6.0', '7.0', '8.0']}
     executable_cmd = downburst_executable()
+    environment_dict = downburst_environment()
     if not executable_cmd:
         log.warn("Downburst not found!")
         log.info('Using default values for supported os_type/os_version')
         return default_table
     try:
-        output = subprocess.check_output([executable_cmd, 'list-json'])
+        log.debug(executable_cmd)
+        output = subprocess.check_output([executable_cmd, 'list-json'],
+                                                        env=environment_dict)
         downburst_data = json.loads(output)
         return downburst_data
     except (subprocess.CalledProcessError, OSError):