xcat2 / xcat-inventory

An inventory tool for xcat cluster
8 stars 16 forks source link

support --env-file option to import env variables #164

Closed xuweibj closed 5 years ago

xuweibj commented 5 years ago

149

UT:

# xcat-inventory import -h
usage: xcat-inventory import [-t <type>] [-o <name>] [-f <path>]
                             [-d <directory>] [-s <version>] [--dry] [-c]
                             [-e <env_var>] [--env-file <env_file>]

Import inventory file to xcat database

Arguments:
  -t <type>, --type <type>
                        comma "," delimited types of the objects to import,
                        valid values: node,credential,passwd,prodkey,site,netw
                        orkconn,network,zone,route,osimage,policy. If not
                        specified, all objects in the inventory file will be
                        imported
  -o <name>, --objects <name>
                        names of the objects to import, delimited with
                        Comma(,). If not specified, all objects of the
                        specified type in the inventory file will be imported
  -f <path>, --path <path>
                        path of the inventory file to import
  -d <directory>, --dir <directory>
                        path of the inventory directory
  -s <version>, --schema-version <version>
                        schema version of the inventory file. Valid schema
                        versions: latest,1.0. If not specified, the "latest"
                        schema version will be used
  --dry                 Dry run mode, nothing will be commited to xcat
                        database
  -c, --clean           clean mode. IF specified, all objects other than the
                        ones to import will be removed
  -e <env_var>, --env <env_var>
                        the values of variables in object definitions(only
                        available for osimage object), syntax: "<variable
                        name>=<variable value>" , this option can be used
                        multiple times to specify multiple variables
  --env-file <env_file>
                        the variable file to set values for variables in
                        inventory file during import. When specified multiple
                        times, the variables in the variable file will
                        overwrite any existing variable. When used with
                        -e option together, the variable value specified
                        with -e will take precedence.
# cat /tmp/env.yaml
GITREPO: /opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/gitrepo
SWDIR: /opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/swdir

# xcat-inventory import -f /opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/test.environments.osimage.update.json --env-file /tmp/env.yaml
loading inventory date in "/opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/test.environments.osimage.update.json"
start to import "osimage" type objects
 preprocessing "osimage" type objects
 writting "osimage" type objects
Inventory import successfully!

#  lsdef -t osimage test.environments.osimage
Object name: test.environments.osimage
    environvar=GITREPO=/opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/gitrepo,OBJNAME=test.environments.osimage,SWDIR=/opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/swdir
    imagetype=linux
    osarch=ppc64le
    osdistroname=rhels7.5-alternate-ppc64le
    osname=Linux
    osvers=rhels7.5-alternate
    otherpkgdir=/opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/swdir/otherpkgdir/
    otherpkglist=/opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/gitrepo/otherpkglist/test1.otherpkglist,/opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/gitrepo/otherpkglist/test2.otherpkglist,
    permission=755
    pkgdir=/install/rhels7.5-alternate/ppc64le,/opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/swdir/pkgdir/
    pkglist=/opt/xcat/share/xcat/netboot/rh/compute.rhels7.ppc64le.pkglist,/opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/gitrepo/pkglist/test1.pkglist,/opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/gitrepo/pkglist/test2.pkglist
    postinstall=/opt/xcat/share/xcat/netboot/rh/compute.rhels7.ppc64le.postinstall,/opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/gitrepo/postinstall/test1.postinstall
    profile=compute
    provmethod=netboot
    rootimgdir=/install/custom/test.environments.osimage
    synclists=/opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/gitrepo/syncfiles/synclist
    usercomment=rhels7.5,test_environment_variables

Load yaml file failed:

# xcat-inventory import -f /opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/test.environments.osimage.update.json --env-file /tmp/env
Error: Failed to load yaml file '/tmp/env', please check ...

Run with -e option:

# xcat-inventory import -f /opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/test.environments.osimage.update.json --env-file /tmp/env.yaml -e SWDIR=/opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/swdir11111
loading inventory date in "/opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/test.environments.osimage.update.json"
start to import "osimage" type objects
 preprocessing "osimage" type objects
 writting "osimage" type objects
Inventory import successfully!

#  lsdef -t osimage test.environments.osimage
Object name: test.environments.osimage
    environvar=GITREPO=/opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/gitrepo,OBJNAME=test.environments.osimage,SWDIR=/opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/swdir11111
    imagetype=linux
    osarch=ppc64le
    osdistroname=rhels7.5-alternate-ppc64le
    osname=Linux
    osvers=rhels7.5-alternate
    otherpkgdir=/opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/swdir11111/otherpkgdir/
    otherpkglist=/opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/gitrepo/otherpkglist/test1.otherpkglist,/opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/gitrepo/otherpkglist/test2.otherpkglist,
    permission=755
    pkgdir=/install/rhels7.5-alternate/ppc64le,/opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/swdir11111/pkgdir/  --------------- set value by -e option
    pkglist=/opt/xcat/share/xcat/netboot/rh/compute.rhels7.ppc64le.pkglist,/opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/gitrepo/pkglist/test1.pkglist,/opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/gitrepo/pkglist/test2.pkglist
    postinstall=/opt/xcat/share/xcat/netboot/rh/compute.rhels7.ppc64le.postinstall,/opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/gitrepo/postinstall/test1.postinstall
    profile=compute
    provmethod=netboot
    rootimgdir=/install/custom/test.environments.osimage
    synclists=/opt/xcat/share/xcat/tools/autotest/testcase/xcat-inventory/templates/environment/gitrepo/syncfiles/synclist
    usercomment=rhels7.5,test_environment_variables
immarvin commented 5 years ago

agree to merge