mirror of https://github.com/apache/cloudstack.git
Some bug fixes
Some more tests store vmpassword functionally working Tests for store password
This commit is contained in:
parent
4c5113b9e5
commit
680454dfdf
|
|
@ -89,9 +89,14 @@ class CsFile:
|
|||
|
||||
def load(self):
|
||||
self.new_config = []
|
||||
for line in open(self.filename):
|
||||
self.new_config.append(line)
|
||||
logging.debug("Reading file %s" % self.filename)
|
||||
try:
|
||||
for line in open(self.filename):
|
||||
self.new_config.append(line)
|
||||
except IOError:
|
||||
logging.debug("File %s does not exist" % self.filename)
|
||||
return
|
||||
else:
|
||||
logging.debug("Reading file %s" % self.filename)
|
||||
|
||||
def is_changed(self):
|
||||
return self.changed
|
||||
|
|
@ -243,6 +248,30 @@ class CsProcess(object):
|
|||
self.pid.append(re.split("\s+", i)[1])
|
||||
return len(self.pid) > 0
|
||||
|
||||
class CsPassword(object):
|
||||
"""
|
||||
Update the password cache
|
||||
|
||||
A stupid step really as we should just rewrite the password server to
|
||||
use the databag
|
||||
"""
|
||||
cache = "/var/cache/cloud/passwords"
|
||||
|
||||
def __init__(self):
|
||||
db = dataBag()
|
||||
db.setKey("vmpassword")
|
||||
db.load()
|
||||
dbag = db.getDataBag()
|
||||
file = CsFile(self.cache)
|
||||
for item in dbag:
|
||||
if item == "id":
|
||||
continue
|
||||
self.update(file, item, dbag[item])
|
||||
file.commit()
|
||||
|
||||
def update(self, file, ip, password):
|
||||
file.search("%s=" % ip, "%s=%s" % (ip, password))
|
||||
|
||||
class CsApp:
|
||||
def __init__(self, ip):
|
||||
self.dev = ip.getDevice()
|
||||
|
|
@ -615,7 +644,6 @@ class CsIP:
|
|||
# Delete any ips that are configured but not in the bag
|
||||
def compare(self, bag):
|
||||
if len(self.iplist) > 0 and (not self.dev in bag.keys() or len(bag[self.dev]) == 0):
|
||||
print "Gets here"
|
||||
# Remove all IPs on this device
|
||||
logging.info("Will remove all configured addresses on device %s", self.dev)
|
||||
self.delete("all")
|
||||
|
|
@ -625,7 +653,6 @@ class CsIP:
|
|||
# This condition should not really happen but did :)
|
||||
# It means an apache file got orphaned after a guest network address was deleted
|
||||
if len(self.iplist) == 0 and (not self.dev in bag.keys() or len(bag[self.dev]) == 0):
|
||||
print self.dev
|
||||
app = CsApache(self)
|
||||
app.remove()
|
||||
|
||||
|
|
@ -660,6 +687,8 @@ def main(argv):
|
|||
format='%(asctime)s %(message)s')
|
||||
|
||||
# we need to parse the cmd_line often, cloudstack might change it between reboots
|
||||
|
||||
# TODO - Take this out --------------------------------------------------------------------- #
|
||||
cmdLine = dataBag()
|
||||
cmdLine.setKey("cmd_line")
|
||||
cmdLine.load()
|
||||
|
|
@ -683,6 +712,7 @@ def main(argv):
|
|||
controlIp["nic_dev_id"] = 0
|
||||
controlIp["nw_type"] = "control"
|
||||
merge(dbag, controlIp)
|
||||
# ----------------------------------------------------------------------------------------- #
|
||||
|
||||
|
||||
for dev in CsDevice('').list():
|
||||
|
|
@ -704,6 +734,7 @@ def main(argv):
|
|||
logging.info("Address %s on device %s not configured", ip.ip(), dev)
|
||||
if CsDevice(dev).waitfordevice():
|
||||
ip.configure()
|
||||
CsPassword()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
from pprint import pprint
|
||||
from netaddr import *
|
||||
|
||||
def merge(dbag, data):
|
||||
"""
|
||||
Track vm passwords
|
||||
"""
|
||||
dbag[data['ip_address']] = data['password']
|
||||
return dbag
|
||||
|
|
@ -95,7 +95,7 @@ class updateDataBag:
|
|||
return cs_guestnetwork.merge(dbag, self.qFile.data)
|
||||
|
||||
def processVMpassword(self, dbag):
|
||||
dbag = cs_vmp.merge(dbag, self.qFile.data)
|
||||
return cs_vmp.merge(dbag, self.qFile.data)
|
||||
|
||||
def processIP(self, dbag):
|
||||
for ip in self.qFile.data["ip_address"]:
|
||||
|
|
|
|||
|
|
@ -136,6 +136,18 @@ class UpdateConfigTestCase(SystemVMTestCase):
|
|||
"type":"guestnetwork"
|
||||
}
|
||||
self.guest_network(config)
|
||||
passw = { "172.16.1.20" : "20",
|
||||
"172.16.1.21" : "21",
|
||||
"172.16.1.22" : "22"
|
||||
}
|
||||
self.check_password(passw)
|
||||
|
||||
passw = { "172.16.1.20" : "120",
|
||||
"172.16.1.21" : "121",
|
||||
"172.16.1.22" : "122"
|
||||
}
|
||||
self.check_password(passw)
|
||||
|
||||
config = { "add":True,
|
||||
"mac_address":"02:00:56:36:00:02",
|
||||
"device":"eth4",
|
||||
|
|
@ -149,6 +161,20 @@ class UpdateConfigTestCase(SystemVMTestCase):
|
|||
}
|
||||
self.guest_network(config)
|
||||
|
||||
def check_password(self,passw):
|
||||
for val in passw:
|
||||
self.add_password(val, passw[val])
|
||||
for val in passw:
|
||||
assert file.has_line("/var/cache/cloud/passwords", "%s=%s" % (val, passw[val]))
|
||||
|
||||
def add_password(self, ip, password):
|
||||
config = { "ip_address": ip,
|
||||
"password":password,
|
||||
"type":"vmpassword"
|
||||
}
|
||||
self.update_config(config)
|
||||
assert file.has_line("/var/cache/cloud/passwords", "%s=%s" % (ip, password))
|
||||
|
||||
def guest_network(self,config):
|
||||
self.update_config(config)
|
||||
assert ip.has_ip("%s/%s" % (config['router_guest_ip'], config['cidr']), config['device'])
|
||||
|
|
|
|||
Loading…
Reference in New Issue