1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
''' Test Basic ceed/codi api'''
import unittest
import re
import subprocess
import utils.ceedutil as ceedutil
# This test set ASSUMES the initial scripts have been run and therefore we have
# 1) 1 codi container named codi-test
# 2) 4 toolchain containers named test-toolchain-test[0-3]
class CeedCommandsTests(unittest.TestCase):
''' Base class for testing ceed '''
def setUp(self):
''' Define some unique data for validation '''
self.dockerAddress = ceedutil.getDockerAddress().strip()
self.tbase=ceedutil.ToolchainNameBase
self.tnum=ceedutil.ToolchainNumber
def tearDown(self):
''' Destroy unique data '''
self.dockerAddress = None
def test_command(self):
''' Get Output from simple command'''
SUBSTRING="/bin/bash"
try:
p = subprocess.Popen(["ceed/ceed","-i",self.dockerAddress,"-d",self.tbase+"0", "-g","which bash"],stdout=subprocess.PIPE)
except subprocess.CalledProcessError as e:
print e.output
self.assertTrue(False)
success=False
output=p.communicate()[0]
for line in output.split('\n'):
if line.find(SUBSTRING) >= 0:
success=True
break
self.assertTrue(success)
def test_command_all(self):
''' Get Output from simple command for all containers'''
SUBSTRING="/bin/bash"
successAll=True
for i in range(self.tnum):
try:
p = subprocess.Popen(["ceed/ceed","-i",self.dockerAddress,"-d",self.tbase+str(i), "-g","which bash"],stdout=subprocess.PIPE)
except subprocess.CalledProcessError as e:
print e.output
self.assertTrue(False)
success=False
output=p.communicate()[0]
for line in output.split('\n'):
if line.find(SUBSTRING) >= 0:
success=True
break
successAll&=success
self.assertTrue(successAll)
def test_command_args_switch(self):
''' Get Output from simple command using argument switch'''
SUBSTRING="/bin/bash"
try:
p = subprocess.Popen(["ceed/ceed","-i",self.dockerAddress,"-d",self.tbase+"0", "-r","bash","-g","which"],stdout=subprocess.PIPE)
except subprocess.CalledProcessError as e:
print e.output
self.assertTrue(False)
success=False
output=p.communicate()[0]
for line in output.split('\n'):
if line.find(SUBSTRING) >= 0:
success=True
break
self.assertTrue(success)
def test_command_env_inline(self):
''' Pass env as Q=R cmd'''
SUBSTRING="FROGS=FRIENDS"
try:
p = subprocess.Popen(["ceed/ceed","-i",self.dockerAddress,"-d",self.tbase+"0", "-g","FROGS=FRIENDS printenv"],stdout=subprocess.PIPE)
except subprocess.CalledProcessError as e:
print e.output
self.assertTrue(False)
success=False
output=p.communicate()[0]
for line in output.split('\n'):
if line.find(SUBSTRING) >= 0:
success=True
break
self.assertTrue(success)
# This will be added when the -e flag is fixed
# def test_command_env_as_argument(self):
# ''' Pass env using the -e switch to cmd'''
# SUBSTRING="FROGS=FRIENDS"
# try:
# p = subprocess.Popen(["ceed/ceed","-i",self.dockerAddress,"-d",self.tbase+"0", "-e","FROGS=FRIENDS","-g","printenv"],stdout=subprocess.PIPE)
# except subprocess.CalledProcessError as e:
# print e.output
# self.assertTrue(False)
# success=False
# output=p.communicate()[0]
# for line in output.split('\n'):
# if line.find(SUBSTRING) >= 0:
# success=True
# break
# self.assertTrue(success)
|