Merge ~mthaddon/charm-mongodb/+git/mongodb-charm:lint-fixes into ~mongodb-charmers/charm-mongodb:master
- Git
- lp:~mthaddon/charm-mongodb/+git/mongodb-charm
- lint-fixes
- Merge into master
Proposed by
Tom Haddon
Status: | Merged |
---|---|
Approved by: | Tom Haddon |
Approved revision: | 7f30a2db9070487d5f76a47017b8bcddd65f87c4 |
Merged at revision: | f478e62856504dc484dfdc005fb368bb29fbb727 |
Proposed branch: | ~mthaddon/charm-mongodb/+git/mongodb-charm:lint-fixes |
Merge into: | ~mongodb-charmers/charm-mongodb:master |
Diff against target: |
195 lines (+25/-25) 1 file modified
hooks/hooks.py (+25/-25) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Stuart Bishop (community) | Approve | ||
Review via email: mp+359932@code.launchpad.net |
Commit message
Fix lint with exception of complexity failures
Description of the change
Fix lint with exception of complexity failures
To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote : | # |
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote : | # |
Change successfully merged at revision f478e62856504dc
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/hooks/hooks.py b/hooks/hooks.py | |||
2 | index 08a7d62..c23198b 100755 | |||
3 | --- a/hooks/hooks.py | |||
4 | +++ b/hooks/hooks.py | |||
5 | @@ -279,7 +279,6 @@ def mongodb_conf(config_data=None): | |||
6 | 279 | config.append("bind_ip = 0.0.0.0") | 279 | config.append("bind_ip = 0.0.0.0") |
7 | 280 | config.append("") | 280 | config.append("") |
8 | 281 | 281 | ||
9 | 282 | |||
10 | 283 | # port | 282 | # port |
11 | 284 | config.append("port = %d" % config_data['port']) | 283 | config.append("port = %d" % config_data['port']) |
12 | 285 | config.append("") | 284 | config.append("") |
13 | @@ -594,6 +593,7 @@ def enable_replset(replicaset_name=None): | |||
14 | 594 | finally: | 593 | finally: |
15 | 595 | return retVal | 594 | return retVal |
16 | 596 | 595 | ||
17 | 596 | |||
18 | 597 | def remove_replset_from_upstart(): | 597 | def remove_replset_from_upstart(): |
19 | 598 | """Removes replicaset configuration from upstart. | 598 | """Removes replicaset configuration from upstart. |
20 | 599 | """ | 599 | """ |
21 | @@ -602,7 +602,7 @@ def remove_replset_from_upstart(): | |||
22 | 602 | 602 | ||
23 | 603 | if re.search(' --replSet', mongodb_init_config, | 603 | if re.search(' --replSet', mongodb_init_config, |
24 | 604 | re.MULTILINE) is not None: | 604 | re.MULTILINE) is not None: |
26 | 605 | mongodb_init_config = re.sub(' --replSet .\w+', '', | 605 | mongodb_init_config = re.sub(r' --replSet .\w+', '', |
27 | 606 | mongodb_init_config) | 606 | mongodb_init_config) |
28 | 607 | retVal = update_file(default_mongodb_init_config, mongodb_init_config) | 607 | retVal = update_file(default_mongodb_init_config, mongodb_init_config) |
29 | 608 | except Exception, e: | 608 | except Exception, e: |
30 | @@ -634,7 +634,7 @@ def remove_rest_from_upstart(): | |||
31 | 634 | try: | 634 | try: |
32 | 635 | mongodb_init_config = open(default_mongodb_init_config).read() | 635 | mongodb_init_config = open(default_mongodb_init_config).read() |
33 | 636 | if re.search(' --rest ', mongodb_init_config, | 636 | if re.search(' --rest ', mongodb_init_config, |
35 | 637 | re.MULTILINE) is not None: | 637 | re.MULTILINE) is not None: |
36 | 638 | mongodb_init_config = regex_sub([(' --rest ', ' ')], | 638 | mongodb_init_config = regex_sub([(' --rest ', ' ')], |
37 | 639 | mongodb_init_config) | 639 | mongodb_init_config) |
38 | 640 | retVal = update_file(default_mongodb_init_config, mongodb_init_config) | 640 | retVal = update_file(default_mongodb_init_config, mongodb_init_config) |
39 | @@ -684,10 +684,10 @@ def configsvr_status(wait_for=default_wait_for, max_tries=default_max_tries): | |||
40 | 684 | config_data = config() | 684 | config_data = config() |
41 | 685 | current_try = 0 | 685 | current_try = 0 |
42 | 686 | 686 | ||
47 | 687 | while (process_check_pidfile('/var/run/mongodb/configsvr.pid') != | 687 | while (process_check_pidfile('/var/run/mongodb/configsvr.pid') != ( |
48 | 688 | (None, None)) and not port_check( | 688 | None, None)) and not port_check( |
49 | 689 | unit_get('private-address'), | 689 | unit_get('private-address'), |
50 | 690 | config_data['config_server_port']) and current_try < max_tries: | 690 | config_data['config_server_port']) and current_try < max_tries: |
51 | 691 | 691 | ||
52 | 692 | juju_log("configsvr_status: Waiting for Config Server to be ready ...") | 692 | juju_log("configsvr_status: Waiting for Config Server to be ready ...") |
53 | 693 | time.sleep(wait_for) | 693 | time.sleep(wait_for) |
54 | @@ -775,8 +775,8 @@ def enable_configsvr(config_data, wait_for=default_wait_for, | |||
55 | 775 | def mongos_status(wait_for=default_wait_for, max_tries=default_max_tries): | 775 | def mongos_status(wait_for=default_wait_for, max_tries=default_max_tries): |
56 | 776 | config_data = config() | 776 | config_data = config() |
57 | 777 | current_try = 0 | 777 | current_try = 0 |
60 | 778 | while (process_check_pidfile('/var/run/mongodb/mongos.pid') != | 778 | while (process_check_pidfile('/var/run/mongodb/mongos.pid') != ( |
61 | 779 | (None, None)) and not port_check( | 779 | None, None)) and not port_check( |
62 | 780 | unit_get('private-address'), | 780 | unit_get('private-address'), |
63 | 781 | config_data['mongos_port']) and current_try < max_tries: | 781 | config_data['mongos_port']) and current_try < max_tries: |
64 | 782 | 782 | ||
65 | @@ -784,8 +784,8 @@ def mongos_status(wait_for=default_wait_for, max_tries=default_max_tries): | |||
66 | 784 | time.sleep(wait_for) | 784 | time.sleep(wait_for) |
67 | 785 | current_try += 1 | 785 | current_try += 1 |
68 | 786 | retVal = \ | 786 | retVal = \ |
71 | 787 | (process_check_pidfile('/var/run/mongodb/mongos.pid') != | 787 | (process_check_pidfile('/var/run/mongodb/mongos.pid') != ( |
72 | 788 | (None, None)) == port_check( | 788 | None, None)) == port_check( |
73 | 789 | unit_get('private-address'), | 789 | unit_get('private-address'), |
74 | 790 | config_data['mongos_port']) is True | 790 | config_data['mongos_port']) is True |
75 | 791 | 791 | ||
76 | @@ -876,9 +876,8 @@ def restart_mongod(wait_for=default_wait_for, max_tries=default_max_tries): | |||
77 | 876 | if not service('start', 'mongodb'): | 876 | if not service('start', 'mongodb'): |
78 | 877 | return False | 877 | return False |
79 | 878 | 878 | ||
83 | 879 | while (service('status', 'mongodb') and | 879 | while (service('status', 'mongodb') and not port_check( |
84 | 880 | not port_check(my_hostname, my_port) and | 880 | my_hostname, my_port) and current_try < max_tries): |
82 | 881 | current_try < max_tries): | ||
85 | 882 | juju_log( | 881 | juju_log( |
86 | 883 | "restart_mongod: Waiting for MongoDB to be ready ({}/{})".format( | 882 | "restart_mongod: Waiting for MongoDB to be ready ({}/{})".format( |
87 | 884 | current_try, max_tries)) | 883 | current_try, max_tries)) |
88 | @@ -1008,7 +1007,7 @@ def config_changed(): | |||
89 | 1008 | sys.exit(1) | 1007 | sys.exit(1) |
90 | 1009 | 1008 | ||
91 | 1010 | # current ports | 1009 | # current ports |
93 | 1011 | current_mongodb_port = re.search('^#*port\s+=\s+(\w+)', | 1010 | current_mongodb_port = re.search(r'^#*port\s+=\s+(\w+)', |
94 | 1012 | mongodb_config, | 1011 | mongodb_config, |
95 | 1013 | re.MULTILINE).group(1) | 1012 | re.MULTILINE).group(1) |
96 | 1014 | 1013 | ||
97 | @@ -1087,7 +1086,7 @@ def config_changed(): | |||
98 | 1087 | juju_log("config_changed: Exception: %s" % str(e)) | 1086 | juju_log("config_changed: Exception: %s" % str(e)) |
99 | 1088 | 1087 | ||
100 | 1089 | if configsvr_pid is not None: | 1088 | if configsvr_pid is not None: |
102 | 1090 | configsvr_port = re.search('--port (\w+)', configsvr_cmd_line).group(2) | 1089 | configsvr_port = re.search(r'--port (\w+)', configsvr_cmd_line).group(2) |
103 | 1091 | disable_configsvr(configsvr_port) | 1090 | disable_configsvr(configsvr_port) |
104 | 1092 | enable_configsvr(config_data['config_server_port']) | 1091 | enable_configsvr(config_data['config_server_port']) |
105 | 1093 | else: | 1092 | else: |
106 | @@ -1103,7 +1102,7 @@ def config_changed(): | |||
107 | 1103 | juju_log("config_changed: Exceptions: %s" % str(e)) | 1102 | juju_log("config_changed: Exceptions: %s" % str(e)) |
108 | 1104 | 1103 | ||
109 | 1105 | if mongos_pid is not None: | 1104 | if mongos_pid is not None: |
111 | 1106 | mongos_port = re.search('--port (\w+)', mongos_cmd_line).group(1) | 1105 | mongos_port = re.search(r'--port (\w+)', mongos_cmd_line).group(1) |
112 | 1107 | disable_mongos(mongos_port) | 1106 | disable_mongos(mongos_port) |
113 | 1108 | enable_mongos(config_data['mongos_port']) | 1107 | enable_mongos(config_data['mongos_port']) |
114 | 1109 | else: | 1108 | else: |
115 | @@ -1139,6 +1138,7 @@ def stop_hook(): | |||
116 | 1139 | juju_log("stop_hook returns: %s" % retVal) | 1138 | juju_log("stop_hook returns: %s" % retVal) |
117 | 1140 | return(retVal) | 1139 | return(retVal) |
118 | 1141 | 1140 | ||
119 | 1141 | |||
120 | 1142 | @hooks.hook('benchmark-relation-joined') | 1142 | @hooks.hook('benchmark-relation-joined') |
121 | 1143 | @hooks.hook('benchmark-relation-changed') | 1143 | @hooks.hook('benchmark-relation-changed') |
122 | 1144 | def benchmark_relation_joined(): | 1144 | def benchmark_relation_joined(): |
123 | @@ -1155,6 +1155,7 @@ def benchmark_relation_joined(): | |||
124 | 1155 | benchmarks = ['perf'] | 1155 | benchmarks = ['perf'] |
125 | 1156 | Benchmark(benchmarks) | 1156 | Benchmark(benchmarks) |
126 | 1157 | 1157 | ||
127 | 1158 | |||
128 | 1158 | @hooks.hook('database-relation-joined') | 1159 | @hooks.hook('database-relation-joined') |
129 | 1159 | def database_relation_joined(): | 1160 | def database_relation_joined(): |
130 | 1160 | juju_log("database_relation_joined") | 1161 | juju_log("database_relation_joined") |
131 | @@ -1221,7 +1222,7 @@ def rs_add(host): | |||
132 | 1221 | 1222 | ||
133 | 1222 | for i in xrange(MONGO_CLIENT_RETRIES): | 1223 | for i in xrange(MONGO_CLIENT_RETRIES): |
134 | 1223 | c = MongoClient('localhost') | 1224 | c = MongoClient('localhost') |
136 | 1224 | cmd_output = subprocess.check_output(cmd_line) | 1225 | subprocess.check_output(cmd_line) |
137 | 1225 | r = run_admin_command(c, 'replSetGetStatus') | 1226 | r = run_admin_command(c, 'replSetGetStatus') |
138 | 1226 | members = r["members"] | 1227 | members = r["members"] |
139 | 1227 | ok = [m for m in members if m['name'] == host and m['state'] == MONGO_SECONDARY] | 1228 | ok = [m for m in members if m['name'] == host and m['state'] == MONGO_SECONDARY] |
140 | @@ -1285,8 +1286,8 @@ def get_replicaset_status(): | |||
141 | 1285 | # if 'self' was not found in the output, then log a warning and print | 1286 | # if 'self' was not found in the output, then log a warning and print |
142 | 1286 | # the output given by replSetGetStatus | 1287 | # the output given by replSetGetStatus |
143 | 1287 | r_pretty = pprint.pformat(r) | 1288 | r_pretty = pprint.pformat(r) |
146 | 1288 | juju_log('get_replicaset_status() failed to get replicaset state:' + | 1289 | juju_log('get_replicaset_status() failed to get replicaset state: ' |
147 | 1289 | r_pretty, level=WARNING) | 1290 | '%s' % r_pretty, level=WARNING) |
148 | 1290 | return 'Unknown replica set state' | 1291 | return 'Unknown replica set state' |
149 | 1291 | 1292 | ||
150 | 1292 | except OperationFailure as e: | 1293 | except OperationFailure as e: |
151 | @@ -1296,6 +1297,7 @@ def get_replicaset_status(): | |||
152 | 1296 | else: | 1297 | else: |
153 | 1297 | return str(e) | 1298 | return str(e) |
154 | 1298 | 1299 | ||
155 | 1300 | |||
156 | 1299 | def get_mongod_version(): | 1301 | def get_mongod_version(): |
157 | 1300 | """ Connects to mongod and get the db.version() output | 1302 | """ Connects to mongod and get the db.version() output |
158 | 1301 | Mainly used for application_set_version in config-changed hook | 1303 | Mainly used for application_set_version in config-changed hook |
159 | @@ -1347,7 +1349,6 @@ def replica_set_relation_changed(): | |||
160 | 1347 | juju_log('replica_set_relation_changed-finish') | 1349 | juju_log('replica_set_relation_changed-finish') |
161 | 1348 | 1350 | ||
162 | 1349 | 1351 | ||
163 | 1350 | |||
164 | 1351 | @hooks.hook('replica-set-relation-departed') | 1352 | @hooks.hook('replica-set-relation-departed') |
165 | 1352 | def replica_set_relation_departed(): | 1353 | def replica_set_relation_departed(): |
166 | 1353 | juju_log('replica_set_relation_departed-start') | 1354 | juju_log('replica_set_relation_departed-start') |
167 | @@ -1546,9 +1547,9 @@ def update_nrpe_config(): | |||
168 | 1546 | current_unit = local_unit() | 1547 | current_unit = local_unit() |
169 | 1547 | 1548 | ||
170 | 1548 | if lsb_release()['DISTRIB_RELEASE'] > '15.04': | 1549 | if lsb_release()['DISTRIB_RELEASE'] > '15.04': |
172 | 1549 | check_mongo_script='check_systemd.py mongodb' | 1550 | check_mongo_script = 'check_systemd.py mongodb' |
173 | 1550 | else: | 1551 | else: |
175 | 1551 | check_mongo_script='check_upstart_job mongodb' | 1552 | check_mongo_script = 'check_upstart_job mongodb' |
176 | 1552 | 1553 | ||
177 | 1553 | nrpe.add_check( | 1554 | nrpe.add_check( |
178 | 1554 | shortname='mongodb', | 1555 | shortname='mongodb', |
179 | @@ -1598,7 +1599,6 @@ def update_status(): | |||
180 | 1598 | return workload | 1599 | return workload |
181 | 1599 | 1600 | ||
182 | 1600 | 1601 | ||
183 | 1601 | |||
184 | 1602 | def run(command, exit_on_error=True): | 1602 | def run(command, exit_on_error=True): |
185 | 1603 | '''Run a command and return the output.''' | 1603 | '''Run a command and return the output.''' |
186 | 1604 | try: | 1604 | try: |
187 | @@ -1709,7 +1709,7 @@ def volume_get_volume_id(): | |||
188 | 1709 | # shell helper | 1709 | # shell helper |
189 | 1710 | def volume_init_and_mount(volid): | 1710 | def volume_init_and_mount(volid): |
190 | 1711 | juju_log("Initialize and mount volume") | 1711 | juju_log("Initialize and mount volume") |
192 | 1712 | command = ("scripts/volume-common.sh call " + | 1712 | command = ("scripts/volume-common.sh call " |
193 | 1713 | "volume_init_and_mount %s" % volid) | 1713 | "volume_init_and_mount %s" % volid) |
194 | 1714 | run(command) | 1714 | run(command) |
195 | 1715 | return True | 1715 | return True |
This merge proposal is being monitored by mergebot. Change the status to Approved to merge.