#215 Match debug inventory to dynamic inventory
Merged 5 years ago by astepano. Opened 5 years ago by till.
till/standard-test-roles debug_inv  into  master

@@ -16,6 +16,8 @@ 

  import time

  import distutils.util

  

+ import yaml

+ 

  IDENTITY = """

  -----BEGIN RSA PRIVATE KEY-----

  MIIEpQIBAAKCAQEA1DrTSXQRF8isQQfPfK3U+eFC4zBrjur+Iy15kbHUYUeSHf5S
@@ -111,6 +113,18 @@ 

              "_meta": {"hostvars": variables}}

  

  

+ def write_debug_inventory(file_, host_vars):

+     raw_inventory = {"all": {"children": {"localhost": {"hosts": host_vars},

+                                           "subjects": {"hosts": host_vars},

+                                           }

+                              }

+                      }

+     with open(file_, "w") as ofile:

+         inventory = yaml.dump(raw_inventory, default_flow_style=False)

+         ofile.write(inventory)

+     return inventory

Do we need to return value?

+ 

+ 

  def start_qemu(image, cloudinit, log, portrange=(2222, 5555)):

      for _ in range(10):

          port = random.randint(*portrange)
@@ -228,10 +242,8 @@ 

              }

  

              # Write out a handy inventory file, for our use and for debugging

-             args = " ".join(["{0}='{1}'".format(*item) for item in variables.items()])

              inventory = os.path.join(directory, "inventory")

-             with open(inventory, "w") as f:

-                 f.write("[subjects]\nlocalhost {0}\n".format(args))

+             write_debug_inventory(inventory, {image: variables})

  

              # Wait for ssh to come up

              ping = [
@@ -289,10 +301,7 @@ 

              return None

          variables["ansible_python_interpreter"] = ansible_python_interpreter

          # Update inventory file

-         args = " ".join(["{0}='{1}'".format(*item) for item in variables.items()])

-         inventory = os.path.join(directory, "inventory")

-         with open(inventory, "w") as f:

-             f.write("[subjects]\nlocalhost {0}\n".format(args))

+         write_debug_inventory(inventory, {image: variables})

          return variables

  

      # Daemonize and watch the processes

Create the debug inventory the same way as the live inventory to keep
the behavior the same. This fixes #214.

pretty please pagure-ci rebuild

https://jenkins-fedora-atomic-process.apps.ci.centos.org/job/str_pr_test/129/console

Running: pycodestyle --max-line-length=120 /home/jenkins/workspace/str_pr_test/inventory/standard-inventory-qcow2
/home/jenkins/workspace/str_pr_test/inventory/standard-inventory-qcow2:118:42: E124 closing bracket does not match visual indentation
/home/jenkins/workspace/str_pr_test/inventory/standard-inventory-qcow2:119:29: E124 closing bracket does not match visual indentation
/home/jenkins/workspace/str_pr_test/inventory/standard-inventory-qcow2:120:21: E124 closing bracket does not match visual indentation

rebased onto b2e2f88

5 years ago

I guess the return value is not needed but I also see no harm in having it.

Commit 3ec8892 fixes this pull-request

Pull-Request has been merged by astepano

5 years ago

Pull-Request has been merged by astepano

5 years ago