Fixing bug in GalaxyCLI test; creates temp dir for role_path instead … (#16689)

* Fixing bug in GalaxyCLI test; creates temp dir for role_path instead of installing to /etc/ansible/roles

* Update test_galaxy.py
This commit is contained in:
s-hertel 2016-07-12 16:01:47 -04:00 committed by jctanner
parent c4cff768d9
commit e84ab95733

View file

@ -27,6 +27,7 @@ import ansible
import os import os
import shutil import shutil
import tarfile import tarfile
import tempfile
from mock import patch from mock import patch
@ -46,12 +47,16 @@ class TestGalaxy(unittest.TestCase):
# creating framework for a role # creating framework for a role
gc = GalaxyCLI(args=["init"]) gc = GalaxyCLI(args=["init"])
with patch('sys.argv', ["-c", "delete_me"]): with patch('sys.argv', ["-c", "--offline", "delete_me"]):
gc.parse() gc.parse()
gc.run() gc.run()
cls.role_dir = "./delete_me" cls.role_dir = "./delete_me"
cls.role_name = "delete_me" cls.role_name = "delete_me"
cls.role_path = "/etc/ansible/roles"
# making a temp dir for role installation
cls.role_path = os.path.join(tempfile.mkdtemp(), "roles")
if not os.path.isdir(cls.role_path):
os.makedirs(cls.role_path)
# creating a tar file name for class data # creating a tar file name for class data
cls.role_tar = './delete_me.tar.gz' cls.role_tar = './delete_me.tar.gz'
@ -85,6 +90,8 @@ class TestGalaxy(unittest.TestCase):
os.remove(cls.role_req) os.remove(cls.role_req)
if os.path.exists(cls.role_tar): if os.path.exists(cls.role_tar):
os.remove(cls.role_tar) os.remove(cls.role_tar)
if os.path.isdir(cls.role_path):
shutil.rmtree(cls.role_path)
def setUp(self): def setUp(self):
self.default_args = [] self.default_args = []
@ -111,7 +118,7 @@ class TestGalaxy(unittest.TestCase):
def test_execute_remove(self): def test_execute_remove(self):
# installing role # installing role
gc = GalaxyCLI(args=["install"]) gc = GalaxyCLI(args=["install"])
with patch('sys.argv', ["--offline", "-r", self.role_req]): with patch('sys.argv', ["--offline", "-p", self.role_path, "-r", self.role_req]):
galaxy_parser = gc.parse() galaxy_parser = gc.parse()
gc.run() gc.run()
@ -120,8 +127,8 @@ class TestGalaxy(unittest.TestCase):
self.assertTrue(os.path.exists(role_file)) self.assertTrue(os.path.exists(role_file))
# removing role # removing role
gc.args = ["remove"] gc = GalaxyCLI(args=["remove"])
with patch('sys.argv', ["-c", self.role_name]): with patch('sys.argv', ["-c", "-p", self.role_path, self.role_name]):
galaxy_parser = gc.parse() galaxy_parser = gc.parse()
super(GalaxyCLI, gc).run() super(GalaxyCLI, gc).run()
gc.api = ansible.galaxy.api.GalaxyAPI(gc.galaxy) gc.api = ansible.galaxy.api.GalaxyAPI(gc.galaxy)