Skip to content
This repository was archived by the owner on Jan 19, 2018. It is now read-only.
This repository was archived by the owner on Jan 19, 2018. It is now read-only.

Handle wrong provider name in answers.conf #562

@surajssd

Description

@surajssd

If the provider name for the atomicapp in answers.conf is mistaken(other than docker, kubernetes, openshift, marathon) then it fails giving all the stack trace without any sane error. Re-creating the errorsome condition:

(atomicapp) [vagrant@centos7-adb apache-centos7-atomicapp]$ pwd
/home/vagrant/nulecule-library/apache-centos7-atomicapp
(atomicapp) [vagrant@centos7-adb apache-centos7-atomicapp]$ tree
.
├── answers.conf
├── answers.conf.orig
├── artifacts
│   ├── docker
│   │   └── apache-centos7-atomicapp_run
│   ├── kubernetes
│   │   └── apache-centos7-atomicapp-pod.json
│   └── marathon
│       └── apache-centos7-atomicapp.json
├── Dockerfile
├── Nulecule
└── README.md

4 directories, 8 files
(atomicapp) [vagrant@centos7-adb apache-centos7-atomicapp]$ cat answers.conf
[apache-centos7-atomicapp]
image = centos/httpd
hostport = 80
[general]
namespace = default
provider = something
(atomicapp) [vagrant@centos7-adb apache-centos7-atomicapp]$ sudo atomicapp run . -v
2016-02-16 07:00:14,739 - atomicapp.cli.main - INFO - Action/Mode Selected is: run
2016-02-16 07:00:14,739 - atomicapp.cli.main - DEBUG - Final parsed cmdline: run . -v
2016-02-16 07:00:14,739 - atomicapp.nulecule.main - DEBUG - NuleculeManager init app_path: .
2016-02-16 07:00:14,739 - atomicapp.nulecule.main - DEBUG - NuleculeManager init    image: None
2016-02-16 07:00:14,739 - atomicapp.utils - DEBUG - Loading answers from file: ./answers.conf
2016-02-16 07:00:14,740 - atomicapp.nulecule.main - DEBUG - Request to unpack to None to .
2016-02-16 07:00:14,744 - atomicapp.plugin - DEBUG - Loading providers from /home/vagrant/atomicapp/atomicapp/providers
2016-02-16 07:00:14,744 - atomicapp.plugin - DEBUG - Loading providers from /home/vagrant/atomicapp/atomicapp/providers
2016-02-16 07:00:14,746 - atomicapp.cli.main - ERROR - 'NoneType' object is not callable
Traceback (most recent call last):
  File "/home/vagrant/atomicapp/atomicapp/cli/main.py", line 100, in cli_run
    nm.run(**argdict)
  File "/home/vagrant/atomicapp/atomicapp/nulecule/main.py", line 228, in run
    self.nulecule.run(cli_provider, dryrun)
  File "/home/vagrant/atomicapp/atomicapp/nulecule/base.py", line 148, in run
    provider_key, provider = self.get_provider(provider_key, dryrun)
  File "/home/vagrant/atomicapp/atomicapp/nulecule/lib.py", line 99, in get_provider
    self.get_context(), self.basepath, dry)
TypeError: 'NoneType' object is not callable
(atomicapp) [vagrant@centos7-adb apache-centos7-atomicapp]$

But when --provider is given from command line then it works perfectly fine:

(atomicapp) [vagrant@centos7-adb apache-centos7-atomicapp]$ sudo atomicapp run . --provider=kubrnetes
usage: atomicapp run [-h] [-V] [-v] [-q] [--mode {fetch,run,stop,genanswers}]
                     [--dry-run] [--answers-format {ini,json,xml,yaml}]
                     [--namespace NAMESPACE]
                     [--providertlsverify {True,False}]
                     [--providerconfig PROVIDERCONFIG]
                     [--providercafile PROVIDERCAFILE]
                     [--providerapi PROVIDERAPI] [-a ANSWERS]
                     [--write-answers ANSWERS_OUTPUT]
                     [--provider {docker,kubernetes,openshift,marathon}]
                     [--ask] [--destination DESTINATION]
                     [app_spec]
atomicapp run: error: argument --provider: invalid choice: 'kubrnetes' (choose from 'docker', 'kubernetes', 'openshift', 'marathon')
(atomicapp) [vagrant@centos7-adb apache-centos7-atomicapp]$ sudo atomicapp run . --provider=something
usage: atomicapp run [-h] [-V] [-v] [-q] [--mode {fetch,run,stop,genanswers}]
                     [--dry-run] [--answers-format {ini,json,xml,yaml}]
                     [--namespace NAMESPACE]
                     [--providertlsverify {True,False}]
                     [--providerconfig PROVIDERCONFIG]
                     [--providercafile PROVIDERCAFILE]
                     [--providerapi PROVIDERAPI] [-a ANSWERS]
                     [--write-answers ANSWERS_OUTPUT]
                     [--provider {docker,kubernetes,openshift,marathon}]
                     [--ask] [--destination DESTINATION]
                     [app_spec]
atomicapp run: error: argument --provider: invalid choice: 'something' (choose from 'docker', 'kubernetes', 'openshift', 'marathon')
(atomicapp) [vagrant@centos7-adb apache-centos7-atomicapp]$

The fix is, to raise an error if given provider_key matches none of the existing key in getProvider method of class Plugin in plugin.py. Shortcut to function here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions