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
6exit(0)
7
8import pexpect, sys, plistlib
9
10pl = plistlib.readPlist(sys.argv[1])
11
12win = pl['windows-machine']
13host = win['host']
14user = win['user']
15pw   = win['password']
16
17mhost = sys.argv[2]
18muser = pl['mount']['user']
19mpw   = pl['mount']['password']
20msharename = pl['mount']['share-name']
21
22conn = pexpect.spawn("telnet -l '{0}' {1}".format(user, host), logfile=sys.stdout, timeout=30)
23i = conn.expect(["Welcome to Microsoft Telnet Service"])
24if i != 0:
25    conn.close()
26    print("failed to connect to host\n")
27    exit(1)
28
29i = conn.expect(["password:"])
30if i != 0:
31    conn.close()
32    print("failed to get the password prompt\n")
33    exit(1)
34
35
36conn.sendline(pw + "\r\n")
37
38i = conn.expect(["C:"])
39if i != 0:
40    conn.close()
41    print("failed to get the C: prompt after login\n")
42    exit(1)
43
44
45conn.sendline("net use Z: /delete\r\n")
46i = conn.expect(["C:"])
47if i != 0:
48    conn.close()
49    print("failed to get the C: prompt after unmount\n")
50    exit(1)
51
52conn.sendline("net use Z: \\\\{2}\\{3} {0} /user:{1}\r\n".format(mpw, muser, mhost, msharename))
53i = 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"])
58if i != 0:
59    conn.close()
60    print("Failed mounting the directory\n")
61    exit(1)
62
63i = conn.expect(["C:"])
64if i != 0:
65    conn.close()
66    print("failed to get the C: prompt after unmount\n")
67    exit(1)
68
69conn.sendline("dir Z:\r\n")
70i = conn.expect(["there-is-a-file-here"])
71if i != 0:
72    conn.close()
73    print("file missing\n")
74    exit(1)
75
76i = conn.expect(["C:"])
77if i != 0:
78    conn.close()
79    print("failed to get the C: prompt\n")
80    exit(1)
81
82conn.sendline("net use Z: /delete\r\n")
83i = conn.expect(["C:"])
84if i != 0:
85    conn.close()
86    print("failed to get the C: prompt after unmount\n")
87    exit(1)
88
89
90conn.sendline("exit\r\n")
91
92print("success testing {0}@{1}/{2}".format(muser, mhost, msharename))
93
94
95