Skip to content

code refactoring, ebs volume extension for testnet#150

Open
AndyBoWu wants to merge 4 commits intoharmony-one:masterfrom
AndyBoWu:pr_extend_ebs_testnet
Open

code refactoring, ebs volume extension for testnet#150
AndyBoWu wants to merge 4 commits intoharmony-one:masterfrom
AndyBoWu:pr_extend_ebs_testnet

Conversation

@AndyBoWu
Copy link
Contributor

@AndyBoWu AndyBoWu commented Oct 5, 2019

first part to extend EBS volume to 40 GB for testnet

Copy link

@LeoHChen LeoHChen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initial review. needs further optimization to reduce redundancy.

also, is this script only working for testnet? how about mainnet? why can't we use the same script and different parameter?

import botocore
from botocore.exceptions import ClientError

EBS_size = 40
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a parameter support.

s3_client = boto3.resource('s3')
s3_client.Bucket(bucketname).download_file(remote_file, local_file)

def create_ip_for_each_region(fpath):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use of this function for what? no explanation.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it just parsing for distribution_config file? is there any other code can be reuse?

while line:
if line.rstrip():
ip = line.split()[0]
region_num = line.split()[4][0]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the format of original file, how do you parse it?


def create_ebs_volume_id_each_region(dict_ip):
for region, ip_array in dict_ip.items():
if region == '1':
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why duplicate the code for different region? this is not efficient. Just add a map of region and region_name.


def increase_ebs_volume(dict_ebs):
for region, ebs_id_array in dict_ebs.items():
if region == '1':
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing, please don't duplicate code.

@AndyBoWu AndyBoWu requested a review from fxfactorial November 8, 2019 18:13
dict_region_volid_array = {}

load_dotenv()
GIT_TOKEN = os.getenv('GIT_TOKEN')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can possibly fail, perhaps better to call it during usage

load_dotenv()
GIT_TOKEN = os.getenv('GIT_TOKEN')

profile_array = ['default', 'mainnet-aw']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constants all upper case

def shcmd(cmd, ignore_error=False):
ret = subprocess.call(cmd, shell=True)
if ignore_error == False and ret != 0:
raise RuntimeError("Failed to execute {}. Return code:{}".format(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer python f strings in new code

return output_string

def download_ipfiles_github(ip_array):
for file in ip_array:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't name your variable same name as python builtin names (file)

# local_shard_file_array = [current_dir+"/shard0.txt"]
print(local_shard_file_array)
for item in local_shard_file_array:
fp = open(item)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer with open() as fp so with context handles the .close for you

for item in local_shard_file_array:
fp = open(item)
line = fp.readline()
while line:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc there is a readlines() or read all, no need to do this on own

region = 'us-east-1'
else:
raise ValueError("cannot deduce region from name {}".format(info))
except Exception as e:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why catch exception at all in this case, maybe just let explode

try:
resp = ec2.describe_instances(Filters=[{'Name': 'ip-address', 'Values': [ip]}])
print(resp)
if len(resp["Reservations"]) != 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!= 0 not needed, just len(resp[])

@AndyBoWu AndyBoWu force-pushed the pr_extend_ebs_testnet branch from c08a9f2 to 07f0cfb Compare January 3, 2020 22:20
local_dist_file = temp_dir + '/distribution_config.txt'

dict_ip_per_region = {}
dict_ebs_id_region = {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are the parameters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants