Skip to content

Commit 680454d

Browse files
Ian Southamwilderrodrigues
authored andcommitted
Some bug fixes
Some more tests store vmpassword functionally working Tests for store password
1 parent 4c5113b commit 680454d

4 files changed

Lines changed: 72 additions & 6 deletions

File tree

systemvm/patches/debian/config/opt/cloud/bin/configure.py

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,14 @@ def __init__(self, filename):
8989

9090
def load(self):
9191
self.new_config = []
92-
for line in open(self.filename):
93-
self.new_config.append(line)
94-
logging.debug("Reading file %s" % self.filename)
92+
try:
93+
for line in open(self.filename):
94+
self.new_config.append(line)
95+
except IOError:
96+
logging.debug("File %s does not exist" % self.filename)
97+
return
98+
else:
99+
logging.debug("Reading file %s" % self.filename)
95100

96101
def is_changed(self):
97102
return self.changed
@@ -243,6 +248,30 @@ def find(self):
243248
self.pid.append(re.split("\s+", i)[1])
244249
return len(self.pid) > 0
245250

251+
class CsPassword(object):
252+
"""
253+
Update the password cache
254+
255+
A stupid step really as we should just rewrite the password server to
256+
use the databag
257+
"""
258+
cache = "/var/cache/cloud/passwords"
259+
260+
def __init__(self):
261+
db = dataBag()
262+
db.setKey("vmpassword")
263+
db.load()
264+
dbag = db.getDataBag()
265+
file = CsFile(self.cache)
266+
for item in dbag:
267+
if item == "id":
268+
continue
269+
self.update(file, item, dbag[item])
270+
file.commit()
271+
272+
def update(self, file, ip, password):
273+
file.search("%s=" % ip, "%s=%s" % (ip, password))
274+
246275
class CsApp:
247276
def __init__(self, ip):
248277
self.dev = ip.getDevice()
@@ -615,7 +644,6 @@ def arpPing(self):
615644
# Delete any ips that are configured but not in the bag
616645
def compare(self, bag):
617646
if len(self.iplist) > 0 and (not self.dev in bag.keys() or len(bag[self.dev]) == 0):
618-
print "Gets here"
619647
# Remove all IPs on this device
620648
logging.info("Will remove all configured addresses on device %s", self.dev)
621649
self.delete("all")
@@ -625,7 +653,6 @@ def compare(self, bag):
625653
# This condition should not really happen but did :)
626654
# It means an apache file got orphaned after a guest network address was deleted
627655
if len(self.iplist) == 0 and (not self.dev in bag.keys() or len(bag[self.dev]) == 0):
628-
print self.dev
629656
app = CsApache(self)
630657
app.remove()
631658

@@ -660,6 +687,8 @@ def main(argv):
660687
format='%(asctime)s %(message)s')
661688

662689
# we need to parse the cmd_line often, cloudstack might change it between reboots
690+
691+
# TODO - Take this out --------------------------------------------------------------------- #
663692
cmdLine = dataBag()
664693
cmdLine.setKey("cmd_line")
665694
cmdLine.load()
@@ -683,6 +712,7 @@ def main(argv):
683712
controlIp["nic_dev_id"] = 0
684713
controlIp["nw_type"] = "control"
685714
merge(dbag, controlIp)
715+
# ----------------------------------------------------------------------------------------- #
686716

687717

688718
for dev in CsDevice('').list():
@@ -704,6 +734,7 @@ def main(argv):
704734
logging.info("Address %s on device %s not configured", ip.ip(), dev)
705735
if CsDevice(dev).waitfordevice():
706736
ip.configure()
737+
CsPassword()
707738

708739
if __name__ == "__main__":
709740
main(sys.argv)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from pprint import pprint
2+
from netaddr import *
3+
4+
def merge(dbag, data):
5+
"""
6+
Track vm passwords
7+
"""
8+
dbag[data['ip_address']] = data['password']
9+
return dbag

systemvm/patches/debian/config/opt/cloud/bin/merge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def processGuestNetwork(self, dbag):
9595
return cs_guestnetwork.merge(dbag, self.qFile.data)
9696

9797
def processVMpassword(self, dbag):
98-
dbag = cs_vmp.merge(dbag, self.qFile.data)
98+
return cs_vmp.merge(dbag, self.qFile.data)
9999

100100
def processIP(self, dbag):
101101
for ip in self.qFile.data["ip_address"]:

test/systemvm/test_update_config.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ def test_create_guest_network(self):
136136
"type":"guestnetwork"
137137
}
138138
self.guest_network(config)
139+
passw = { "172.16.1.20" : "20",
140+
"172.16.1.21" : "21",
141+
"172.16.1.22" : "22"
142+
}
143+
self.check_password(passw)
144+
145+
passw = { "172.16.1.20" : "120",
146+
"172.16.1.21" : "121",
147+
"172.16.1.22" : "122"
148+
}
149+
self.check_password(passw)
150+
139151
config = { "add":True,
140152
"mac_address":"02:00:56:36:00:02",
141153
"device":"eth4",
@@ -149,6 +161,20 @@ def test_create_guest_network(self):
149161
}
150162
self.guest_network(config)
151163

164+
def check_password(self,passw):
165+
for val in passw:
166+
self.add_password(val, passw[val])
167+
for val in passw:
168+
assert file.has_line("/var/cache/cloud/passwords", "%s=%s" % (val, passw[val]))
169+
170+
def add_password(self, ip, password):
171+
config = { "ip_address": ip,
172+
"password":password,
173+
"type":"vmpassword"
174+
}
175+
self.update_config(config)
176+
assert file.has_line("/var/cache/cloud/passwords", "%s=%s" % (ip, password))
177+
152178
def guest_network(self,config):
153179
self.update_config(config)
154180
assert ip.has_ip("%s/%s" % (config['router_guest_ip'], config['cidr']), config['device'])

0 commit comments

Comments
 (0)