Revision d0c8c01d qa/qa_config.py
b/qa/qa_config.py | ||
---|---|---|
47 | 47 |
|
48 | 48 |
|
49 | 49 |
def Validate(): |
50 |
if len(cfg['nodes']) < 1:
|
|
50 |
if len(cfg["nodes"]) < 1:
|
|
51 | 51 |
raise qa_error.Error("Need at least one node") |
52 |
if len(cfg['instances']) < 1:
|
|
52 |
if len(cfg["instances"]) < 1:
|
|
53 | 53 |
raise qa_error.Error("Need at least one instance") |
54 | 54 |
if len(cfg["disk"]) != len(cfg["disk-growth"]): |
55 | 55 |
raise qa_error.Error("Config options 'disk' and 'disk-growth' must have" |
... | ... | |
72 | 72 |
|
73 | 73 |
|
74 | 74 |
def GetMasterNode(): |
75 |
return cfg['nodes'][0]
|
|
75 |
return cfg["nodes"][0]
|
|
76 | 76 |
|
77 | 77 |
|
78 | 78 |
def AcquireInstance(): |
... | ... | |
80 | 80 |
|
81 | 81 |
""" |
82 | 82 |
# Filter out unwanted instances |
83 |
tmp_flt = lambda inst: not inst.get('_used', False)
|
|
84 |
instances = filter(tmp_flt, cfg['instances'])
|
|
83 |
tmp_flt = lambda inst: not inst.get("_used", False)
|
|
84 |
instances = filter(tmp_flt, cfg["instances"])
|
|
85 | 85 |
del tmp_flt |
86 | 86 |
|
87 | 87 |
if len(instances) == 0: |
88 | 88 |
raise qa_error.OutOfInstancesError("No instances left") |
89 | 89 |
|
90 | 90 |
inst = instances[0] |
91 |
inst['_used'] = True
|
|
91 |
inst["_used"] = True
|
|
92 | 92 |
return inst |
93 | 93 |
|
94 | 94 |
|
95 | 95 |
def ReleaseInstance(inst): |
96 |
inst['_used'] = False
|
|
96 |
inst["_used"] = False
|
|
97 | 97 |
|
98 | 98 |
|
99 | 99 |
def AcquireNode(exclude=None): |
... | ... | |
105 | 105 |
# Filter out unwanted nodes |
106 | 106 |
# TODO: Maybe combine filters |
107 | 107 |
if exclude is None: |
108 |
nodes = cfg['nodes'][:]
|
|
108 |
nodes = cfg["nodes"][:]
|
|
109 | 109 |
elif isinstance(exclude, (list, tuple)): |
110 |
nodes = filter(lambda node: node not in exclude, cfg['nodes'])
|
|
110 |
nodes = filter(lambda node: node not in exclude, cfg["nodes"])
|
|
111 | 111 |
else: |
112 |
nodes = filter(lambda node: node != exclude, cfg['nodes'])
|
|
112 |
nodes = filter(lambda node: node != exclude, cfg["nodes"])
|
|
113 | 113 |
|
114 |
tmp_flt = lambda node: node.get('_added', False) or node == master
|
|
114 |
tmp_flt = lambda node: node.get("_added", False) or node == master
|
|
115 | 115 |
nodes = filter(tmp_flt, nodes) |
116 | 116 |
del tmp_flt |
117 | 117 |
|
... | ... | |
120 | 120 |
|
121 | 121 |
# Get node with least number of uses |
122 | 122 |
def compare(a, b): |
123 |
result = cmp(a.get('_count', 0), b.get('_count', 0))
|
|
123 |
result = cmp(a.get("_count", 0), b.get("_count", 0))
|
|
124 | 124 |
if result == 0: |
125 |
result = cmp(a['primary'], b['primary'])
|
|
125 |
result = cmp(a["primary"], b["primary"])
|
|
126 | 126 |
return result |
127 | 127 |
|
128 | 128 |
nodes.sort(cmp=compare) |
129 | 129 |
|
130 | 130 |
node = nodes[0] |
131 |
node['_count'] = node.get('_count', 0) + 1
|
|
131 |
node["_count"] = node.get("_count", 0) + 1
|
|
132 | 132 |
return node |
133 | 133 |
|
134 | 134 |
|
135 | 135 |
def ReleaseNode(node): |
136 |
node['_count'] = node.get('_count', 0) - 1 |
|
136 |
node["_count"] = node.get("_count", 0) - 1 |
Also available in: Unified diff