Skip to content

Commit 45e9b59

Browse files
committed
Added/tested startup-config testing for CSR1000V
1 parent 9733d9d commit 45e9b59

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

csr/docker/launch.py

+31-13
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
import vrnetlab
1313

14+
STARTUP_CONFIG_FILE = "/config/startup-config.cfg"
15+
1416

1517
def handle_SIGCHLD(signal, frame):
1618
os.waitpid(-1, os.WNOHANG)
@@ -79,9 +81,7 @@ def create_boot_image(self):
7981
cfg_file.write("exit\r\n")
8082
cfg_file.write("license accept end user agreement\r\n")
8183
cfg_file.write("yes\r\n")
82-
cfg_file.write(
83-
"do license install tftp://10.0.0.2/license.lic\r\n\r\n"
84-
)
84+
cfg_file.write("do license install tftp://10.0.0.2/license.lic\r\n\r\n")
8585

8686
cfg_file.write("platform console serial\r\n\r\n")
8787
cfg_file.write("do clear platform software vnic-if nvtable\r\n\r\n")
@@ -108,9 +108,7 @@ def bootstrap_spin(self):
108108
self.start()
109109
return
110110

111-
(ridx, match, res) = self.tn.expect(
112-
[b"Press RETURN to get started!"], 1
113-
)
111+
(ridx, match, res) = self.tn.expect([b"Press RETURN to get started!"], 1)
114112
if match: # got a match!
115113
if ridx == 0: # login
116114
if self.install_mode:
@@ -122,13 +120,13 @@ def bootstrap_spin(self):
122120

123121
# run main config!
124122
self.bootstrap_config()
123+
self.startup_config()
124+
self.running = True
125125
# close telnet connection
126126
self.tn.close()
127127
# startup time?
128128
startup_time = datetime.datetime.now() - self.start_time
129129
self.logger.info("Startup complete in: %s" % startup_time)
130-
# mark as running
131-
self.running = True
132130
return
133131

134132
# no match, if we saw some output from the router it's probably
@@ -152,8 +150,7 @@ def bootstrap_config(self):
152150

153151
self.wait_write("hostname %s" % (self.hostname))
154152
self.wait_write(
155-
"username %s privilege 15 password %s"
156-
% (self.username, self.password)
153+
"username %s privilege 15 password %s" % (self.username, self.password)
157154
)
158155
self.wait_write("ip domain name example.com")
159156
self.wait_write("crypto key generate rsa modulus 2048")
@@ -172,6 +169,29 @@ def bootstrap_config(self):
172169
self.wait_write("copy running-config startup-config")
173170
self.wait_write("\r", None)
174171

172+
def startup_config(self):
173+
"""Load additional config provided by user."""
174+
175+
if not os.path.exists(STARTUP_CONFIG_FILE):
176+
self.logger.trace(f"Startup config file {STARTUP_CONFIG_FILE} is not found")
177+
return
178+
179+
self.logger.trace(f"Startup config file {STARTUP_CONFIG_FILE} exists")
180+
with open(STARTUP_CONFIG_FILE) as file:
181+
config_lines = file.readlines()
182+
config_lines = [line.rstrip() for line in config_lines]
183+
self.logger.trace(f"Parsed startup config file {STARTUP_CONFIG_FILE}")
184+
185+
self.logger.info(f"Writing lines from {STARTUP_CONFIG_FILE}")
186+
187+
self.wait_write("configure terminal")
188+
# Apply lines from file
189+
for line in config_lines:
190+
self.wait_write(line)
191+
# End and Save
192+
self.wait_write("end")
193+
self.wait_write("copy running-config startup-config")
194+
175195

176196
class CSR(vrnetlab.VR):
177197
def __init__(self, hostname, username, password, nics, conn_mode):
@@ -219,9 +239,7 @@ def install(self):
219239
parser.add_argument("--username", default="vrnetlab", help="Username")
220240
parser.add_argument("--password", default="VR-netlab9", help="Password")
221241
parser.add_argument("--install", action="store_true", help="Install CSR")
222-
parser.add_argument(
223-
"--hostname", default="csr1000v", help="Router Hostname"
224-
)
242+
parser.add_argument("--hostname", default="csr1000v", help="Router Hostname")
225243
parser.add_argument("--nics", type=int, default=9, help="Number of NICS")
226244
parser.add_argument(
227245
"--connection-mode",

0 commit comments

Comments
 (0)