(haproxyData, haCfgSections)
| 70 | return True |
| 71 | |
| 72 | def checkLoadBalance(haproxyData, haCfgSections): |
| 73 | correct = True |
| 74 | for lbSec in haproxyData: |
| 75 | srcServer = lbSec["sourceIp"].replace('.', '_') + "-" + \ |
| 76 | formatPort(lbSec["sourcePortStart"], |
| 77 | lbSec["sourcePortEnd"]) |
| 78 | secName = "listen " + srcServer |
| 79 | |
| 80 | if secName not in haCfgSections: |
| 81 | print("Missing section for load balancing " + secName + "\n") |
| 82 | correct = False |
| 83 | else: |
| 84 | cfgSection = haCfgSections[secName] |
| 85 | if "server" in cfgSection: |
| 86 | if lbSec["algorithm"] != cfgSection["balance"][0]: |
| 87 | print("Incorrect balance method for " + secName + |
| 88 | "Expected : " + lbSec["algorithm"] + |
| 89 | " but found " + cfgSection["balance"][0] + "\n") |
| 90 | correct = False |
| 91 | |
| 92 | bindStr = lbSec["sourceIp"] + ":" + formatPort(lbSec["sourcePortStart"], lbSec["sourcePortEnd"]) |
| 93 | if cfgSection["bind"][0] != bindStr: |
| 94 | print("Incorrect bind string found. Expected " + bindStr + " but found " + cfgSection["bind"][0] + ".") |
| 95 | correct = False |
| 96 | |
| 97 | if (lbSec["sourcePortStart"] == "80" and lbSec["sourcePortEnd"] == "80" and lbSec["keepAliveEnabled"] == "false") \ |
| 98 | or (lbSec["stickiness"].find("AppCookie") != -1 or lbSec["stickiness"].find("LbCookie") != -1): |
| 99 | if not ("mode" in cfgSection and cfgSection["mode"][0] == "http"): |
| 100 | print("Expected HTTP mode but not found") |
| 101 | correct = False |
| 102 | |
| 103 | expectedServerIps = lbSec["vmIps"].split(" ") |
| 104 | for expectedServerIp in expectedServerIps: |
| 105 | pattern = expectedServerIp + ":" + \ |
| 106 | formatPort(lbSec["destPortStart"], |
| 107 | lbSec["destPortEnd"]) |
| 108 | foundPattern = False |
| 109 | for server in cfgSection["server"]: |
| 110 | s = server.split() |
| 111 | if s[0].strip().find(srcServer + "_") == 0 and s[1].strip() == pattern: |
| 112 | foundPattern = True |
| 113 | break |
| 114 | |
| 115 | if not foundPattern: |
| 116 | correct = False |
| 117 | print("Missing load balancing for " + pattern + ". ") |
| 118 | |
| 119 | return correct |
| 120 | |
| 121 | |
| 122 | def main(): |
no test coverage detected