3 # Samba Testing Framework for Unit-testing
9 def get_server_list_from_string(s
):
13 # Format is a list of server:domain\username%password separated
16 for entry
in string
.split(s
, ","):
20 m
= re
.match("(.*):(.*)(\\\\|/)(.*)%(.*)", entry
)
22 raise "badly formed server list entry '%s'" % entry
31 server_list
.append({"platform": osver
.os_version(server
),
33 "administrator": {"username": username
,
35 "password" : password
}})
39 def get_server_list():
40 """Iterate through all sources of server info and append them all
45 # The $STF_SERVERS environment variable
47 if os
.environ
.has_key("STF_SERVERS"):
48 server_list
= server_list
+ \
49 get_server_list_from_string(os
.environ
["STF_SERVERS"])
53 def get_server(platform
= None):
54 """Return configuration information for a server. The platform
55 argument can be a string either 'nt4' or 'nt5' for Windows NT or
56 Windows 2000 servers, or just 'nt' for Windows NT and higher."""
58 server_list
= get_server_list()
60 for server
in server_list
:
62 p
= server
["platform"]
64 if (p
== osver
.PLATFORM_NT4
or p
== osver
.PLATFORM_NT5
):
66 if platform
== "nt4" and p
== osver
.PLATFORM_NT4
:
68 if platform
== "nt5" and p
== osver
.PLATFORM_NT5
:
71 # No filter defined, return first in list
76 def dict_check(sample_dict
, real_dict
):
77 """Check that real_dict contains all the keys present in sample_dict
78 and no extras. Also check that common keys are of them same type."""
79 tmp
= real_dict
.copy()
80 for key
in sample_dict
.keys():
81 # Check existing key and type
82 if not real_dict
.has_key(key
):
83 raise ValueError, "dict does not contain key '%s'" % key
84 if type(sample_dict
[key
]) != type(real_dict
[key
]):
85 raise ValueError, "dict has differing types (%s vs %s) for key " \
86 "'%s'" % (type(sample_dict
[key
]), type(real_dict
[key
]), key
)
87 # Check dictionaries recursively
88 if type(sample_dict
[key
]) == dict:
89 dict_check(sample_dict
[key
], real_dict
[key
])
90 # Delete visited keys from copy
92 # Any keys leftover are present in the real dict but not the sample
95 result
= "dict has extra keys: "
96 for key
in tmp
.keys():
97 result
= result
+ key
+ " "
98 raise ValueError, result
100 if __name__
== "__main__":
101 print get_server(platform
= "nt")