Skip to content

Commit

Permalink
Update blockdevmap.py (sky-uk#88)
Browse files Browse the repository at this point in the history
+ Update blockdevmap.py from upstream to support python2
+ Add check for Ansible <=2.10.6 (2.10.7 has an incompatibility which causes us to fail to delete from Route53)
  • Loading branch information
dseeley-sky authored Apr 16, 2021
1 parent ec23be6 commit c87bb5a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 73 deletions.
26 changes: 14 additions & 12 deletions _dependencies/library/blockdevmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,12 @@
except:
pass

# FileNotFoundError does not exist in python2 - it is an IOError
try:
FileNotFoundError
except NameError:
FileNotFoundError = IOError

try:
from urllib.request import urlopen
except ImportError:
Expand Down Expand Up @@ -412,9 +418,9 @@ def __init__(self, **kwds):
response__block_device_mapping = urlopen('http://169.254.169.254/latest/meta-data/block-device-mapping/')
block_device_mappings = response__block_device_mapping.read().decode().split("\n")
for block_device_mappings__ephemeral_id in [dev for dev in block_device_mappings if dev.startswith('ephemeral')]:
with urlopen("http://169.254.169.254/latest/meta-data/block-device-mapping/" + block_device_mappings__ephemeral_id) as response__ephemeral_device:
block_device_mappings__ephemeral_mapped = response__ephemeral_device.read().decode()
instance_store_map.append({'ephemeral_id': block_device_mappings__ephemeral_id, 'ephemeral_map': block_device_mappings__ephemeral_mapped})
response__ephemeral_device = urlopen("http://169.254.169.254/latest/meta-data/block-device-mapping/" + block_device_mappings__ephemeral_id)
block_device_mappings__ephemeral_mapped = response__ephemeral_device.read().decode()
instance_store_map.append({'ephemeral_id': block_device_mappings__ephemeral_id, 'ephemeral_map': block_device_mappings__ephemeral_mapped})

instance_store_count = 0
self.device_map = self.get_lsblk()
Expand Down Expand Up @@ -473,21 +479,17 @@ def main():
if not (len(sys.argv) > 1 and sys.argv[1] == "console"):
module = AnsibleModule(argument_spec={"cloud_type": {"type": "str", "required": True, "choices": ['aws', 'gcp', 'azure', 'lsblk']}}, supports_check_mode=True)
else:
# For testing without Ansible (e.g on Windows)
class cDummyAnsibleModule():
params = {"cloud_type": "azure"}

class cDummyAnsibleModule(): # For testing without Ansible (e.g on Windows)
def __init__(self):
self.params={}
def exit_json(self, changed, **kwargs):
print(changed, json.dumps(kwargs, sort_keys=True, indent=4, separators=(',', ': ')))

def warn(self, msg):
print("[WARNING]: " + msg)

def fail_json(self, msg):
print("Failed: " + msg)
exit(1)

module = cDummyAnsibleModule()
module.params = {"cloud_type": sys.argv[2]}

if module.params['cloud_type'] == 'aws':
blockdevmap = cAwsMapper(module=module)
Expand All @@ -504,4 +506,4 @@ def fail_json(self, msg):


if __name__ == '__main__':
main()
main()
2 changes: 1 addition & 1 deletion _dependencies/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

- name: Preflight check
block:
- assert: { that: "ansible_version.full is version_compare('2.9', '>=')", fail_msg: "Ansible >=2.9 required." }
- assert: { that: "ansible_version.full is version_compare('2.9.6', '>=') and ansible_version.full is version_compare('2.10.6', '<=')", fail_msg: "2.10.6 >= Ansible >= 2.9.6 required." } #2.10.7 has issue with AWS DNS: https://github.com/ansible-collections/community.aws/issues/523
- assert: { that: "app_name is defined and app_name != ''", fail_msg: "Please define app_name" }
- assert: { that: "app_class is defined and app_class != ''", fail_msg: "Please define app_class" }
- assert: { that: "cluster_vars is defined", fail_msg: "Please define cluster_vars" }
Expand Down
32 changes: 0 additions & 32 deletions redeploy/__common/tasks/powerchange_vms_azure.yml

This file was deleted.

28 changes: 0 additions & 28 deletions redeploy/__common/tasks/powerchange_vms_esxifree.yml

This file was deleted.

0 comments on commit c87bb5a

Please sign in to comment.