/ tests / bin / heimdal-win-mount.py
heimdal-win-mount.py
 1  #!/usr/bin/python
 2  
 3  '''login to windows server, mount a share, check existance of file, umount'''
 4  
 5  # disabled until we have a exepct we can use
 6  exit(0)
 7  
 8  import pexpect, sys, plistlib
 9  
10  pl = plistlib.readPlist(sys.argv[1])
11  
12  win = pl['windows-machine']
13  host = win['host']
14  user = win['user']
15  pw   = win['password']
16  
17  mhost = sys.argv[2]
18  muser = pl['mount']['user']
19  mpw   = pl['mount']['password']
20  msharename = pl['mount']['share-name']
21  
22  conn = pexpect.spawn("telnet -l '{0}' {1}".format(user, host), logfile=sys.stdout, timeout=30)
23  i = conn.expect(["Welcome to Microsoft Telnet Service"])
24  if i != 0:
25      conn.close()
26      print("failed to connect to host\n")
27      exit(1)
28  
29  i = conn.expect(["password:"])
30  if i != 0:
31      conn.close()
32      print("failed to get the password prompt\n")
33      exit(1)
34  
35  
36  conn.sendline(pw + "\r\n")
37  
38  i = conn.expect(["C:"])
39  if i != 0:
40      conn.close()
41      print("failed to get the C: prompt after login\n")
42      exit(1)
43  
44  
45  conn.sendline("net use Z: /delete\r\n")
46  i = conn.expect(["C:"])
47  if i != 0:
48      conn.close()
49      print("failed to get the C: prompt after unmount\n")
50      exit(1)
51  
52  conn.sendline("net use Z: \\\\{2}\\{3} {0} /user:{1}\r\n".format(mpw, muser, mhost, msharename))
53  i = conn.expect(["The command completed successfully",
54                   "The network path was not found",
55                   "The specified network password is not correct",
56                   "System error \d+ has occurred",
57                   "The network connection could not be found"])
58  if i != 0:
59      conn.close()
60      print("Failed mounting the directory\n")
61      exit(1)
62  
63  i = conn.expect(["C:"])
64  if i != 0:
65      conn.close()
66      print("failed to get the C: prompt after unmount\n")
67      exit(1)
68  
69  conn.sendline("dir Z:\r\n")
70  i = conn.expect(["there-is-a-file-here"])
71  if i != 0:
72      conn.close()
73      print("file missing\n")
74      exit(1)
75  
76  i = conn.expect(["C:"])
77  if i != 0:
78      conn.close()
79      print("failed to get the C: prompt\n")
80      exit(1)
81  
82  conn.sendline("net use Z: /delete\r\n")
83  i = conn.expect(["C:"])
84  if i != 0:
85      conn.close()
86      print("failed to get the C: prompt after unmount\n")
87      exit(1)
88  
89  
90  conn.sendline("exit\r\n")
91  
92  print("success testing {0}@{1}/{2}".format(muser, mhost, msharename))
93  
94