Skip to content

Commit deee68c

Browse files
authored
Refactor mirror_image.py tool (#259)
Signed-off-by: Sergio Arroutbi <[email protected]>
1 parent 42276ff commit deee68c

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

tools/cluster_tools/mirror_image.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,18 @@ def get_user_password_from_args(args):
117117
return args.user, args.password
118118
return get_user_password_from_file(args.file_for_user_password)
119119

120-
def launch_node_commands(node, api_server, args):
120+
def launch_chroot_commands(child):
121121
"""
122-
This function launches commands in the node
122+
This function launch chroot command
123123
"""
124-
user, password = get_user_password_from_args(args)
125-
child = pexpect.spawnu('oc debug nodes/' + node, timeout=NODE_CONNECTION_TIMEOUT)
126-
child.logfile_read = sys.stdout
127-
child.expect('# ')
128124
send_pexpect_command(child, '\n', '#')
129125
send_pexpect_command(child, 'chroot /host', '#')
130126
send_pexpect_command(child, '\n', '#')
127+
128+
def launch_cluster_auth_commands(child, args, api_server):
129+
"""
130+
This function launch cluster authentication commands
131+
"""
131132
if args.cluster_password:
132133
send_pexpect_command(child, 'oc login -u kubeadmin -p ' + args.cluster_password +
133134
' ' + api_server, ': ')
@@ -139,6 +140,12 @@ def launch_node_commands(node, api_server, args):
139140
send_pexpect_command(child, 'yes', '#')
140141
else:
141142
send_pexpect_command(child, '\n', '#')
143+
144+
def launch_podman_commands(child, args):
145+
"""
146+
This function launch podman authentication commands
147+
"""
148+
user, password = get_user_password_from_args(args)
142149
send_pexpect_command(child, 'podman login -u kubeadmin -p $(oc whoami -t) ' +
143150
LOCAL_REGISTRY, '#')
144151
send_pexpect_command(child, 'echo', '#')
@@ -151,11 +158,21 @@ def launch_node_commands(node, api_server, args):
151158
send_pexpect_command(child, 'podman images | grep ' + LOCAL_REGISTRY, '#')
152159
send_pexpect_command(child, 'podman push ' + LOCAL_REGISTRY + '/' +
153160
get_image_path(args.original_image), '#')
161+
162+
def launch_node_commands(node, api_server, args):
163+
"""
164+
This function launches commands in the node
165+
"""
166+
child = pexpect.spawnu('oc debug nodes/' + node, timeout=NODE_CONNECTION_TIMEOUT)
167+
child.logfile_read = sys.stdout
168+
child.expect('# ')
169+
launch_chroot_commands(child)
170+
launch_cluster_auth_commands(child, args, api_server)
171+
launch_podman_commands(child, args)
154172
send_pexpect_command(child, 'exit', '#')
155173
sys.stdout.flush()
156174
child.close()
157175

158-
159176
def execute_command(cmd):
160177
"""
161178
This function executes command and returs its result

0 commit comments

Comments
 (0)