summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/data/dhcp (renamed from tests/dhcp)bin328 -> 328 bytes
-rwxr-xr-xtests/data/ext/event.xml1
-rw-r--r--tests/data/ext/sample_ext.zipbin0 -> 878 bytes
-rw-r--r--tests/data/ext/sample_ext/HandlerManifest.json14
-rwxr-xr-xtests/data/ext/sample_ext/sample.py33
-rw-r--r--tests/data/metadata/certificates.json7
-rw-r--r--tests/data/metadata/ext_handler_pkgs.json10
-rw-r--r--tests/data/metadata/ext_handlers.json19
-rw-r--r--tests/data/metadata/ext_handlers_no_ext.json1
-rw-r--r--tests/data/metadata/identity.json4
-rw-r--r--tests/data/ovf-env.xml29
-rw-r--r--tests/data/wire/certs.xml81
-rw-r--r--tests/data/wire/ext_conf.xml46
-rw-r--r--tests/data/wire/ext_conf_no_public.xml46
-rw-r--r--tests/data/wire/ext_conf_no_settings.xml41
-rw-r--r--tests/data/wire/goal_state.xml27
-rw-r--r--tests/data/wire/goal_state_no_ext.xml26
-rw-r--r--tests/data/wire/hosting_env.xml (renamed from tests/test_hostingenv.py)44
-rw-r--r--tests/data/wire/manifest.xml18
-rw-r--r--tests/data/wire/shared_config.xml (renamed from tests/test_sharedconfig.py)39
-rw-r--r--tests/data/wire/sshd_config (renamed from tests/sshd_config)0
-rw-r--r--tests/data/wire/trans_cert19
-rw-r--r--tests/data/wire/trans_prv28
-rw-r--r--tests/data/wire/version_info.xml10
-rw-r--r--tests/distro/__init__.py (renamed from tests/env.py)7
-rw-r--r--tests/distro/test_daemon.py65
-rw-r--r--tests/distro/test_extension.py191
-rw-r--r--tests/distro/test_loader.py (renamed from tests/test_future.py)23
-rw-r--r--tests/distro/test_monitor.py (renamed from tests/test_protocolFactory.py)23
-rw-r--r--tests/distro/test_protocol_util.py89
-rw-r--r--tests/distro/test_provision.py (renamed from tests/test_agent.py)40
-rw-r--r--[-rwxr-xr-x]tests/protocol/__init__.py (renamed from tests/run_all.sh)26
-rw-r--r--tests/protocol/mockmetadata.py61
-rw-r--r--tests/protocol/mockwiredata.py101
-rw-r--r--tests/protocol/test_metadata.py48
-rw-r--r--tests/protocol/test_restapi.py (renamed from tests/test_datacontract.py)3
-rw-r--r--tests/protocol/test_wire.py85
-rw-r--r--tests/test.crt17
-rw-r--r--tests/test.prv15
-rw-r--r--tests/test_certificates.py199
-rw-r--r--tests/test_conf.py69
-rw-r--r--tests/test_deprovision.py54
-rw-r--r--tests/test_dhcp.py68
-rw-r--r--tests/test_distroLoader.py42
-rw-r--r--tests/test_envmon.py52
-rw-r--r--tests/test_event.py53
-rw-r--r--tests/test_ext.py223
-rw-r--r--tests/test_extensionsconfig.py159
-rw-r--r--tests/test_goalstate.py71
-rw-r--r--tests/test_import_waagent.py40
-rw-r--r--tests/test_logger.py100
-rw-r--r--tests/test_metadata.py36
-rw-r--r--tests/test_osutil.py174
-rw-r--r--tests/test_ovfxml.py81
-rw-r--r--tests/test_protocol.py72
-rw-r--r--tests/test_redhat.py49
-rw-r--r--tests/test_resourcedisk.py63
-rw-r--r--tests/test_rest_util.py63
-rw-r--r--tests/test_v1.py203
-rw-r--r--tests/test_v2.py120
-rw-r--r--tests/test_version.py53
-rw-r--r--tests/tools.py133
-rw-r--r--tests/utils/__init__.py19
-rw-r--r--tests/utils/test_file_util.py (renamed from tests/test_file_util.py)32
-rw-r--r--tests/utils/test_rest_util.py126
-rw-r--r--tests/utils/test_shell_util.py (renamed from tests/test_shell_util.py)6
-rw-r--r--tests/utils/test_text_util.py (renamed from tests/test_text_util.py)23
67 files changed, 1426 insertions, 2294 deletions
diff --git a/tests/dhcp b/tests/data/dhcp
index 8c9d127..8c9d127 100644
--- a/tests/dhcp
+++ b/tests/data/dhcp
Binary files differ
diff --git a/tests/data/ext/event.xml b/tests/data/ext/event.xml
new file mode 100755
index 0000000..436de44
--- /dev/null
+++ b/tests/data/ext/event.xml
@@ -0,0 +1 @@
+<Data><Provider id="69B669B9-4AF8-4C50-BDC4-6006FA76E975"/><Event id="1"/><Param Name="OperationSuccess" Value="True" T="mt:bool" /><Param Name="Processors" Value="0" T="mt:uint64" /><Param Name="OpcodeName" Value="" T="mt:wstr" /><Param Name="Version" Value="1.4.1.0" T="mt:wstr" /><Param Name="RoleName" Value="" T="mt:wstr" /><Param Name="IsInternal" Value="False" T="mt:bool" /><Param Name="RAM" Value="0" T="mt:uint64" /><Param Name="ExecutionMode" Value="IAAS" T="mt:wstr" /><Param Name="RoleInstanceName" Value="" T="mt:wstr" /><Param Name="Name" Value="CustomScript" T="mt:wstr" /><Param Name="Message" Value="(01302)Script is finished.&#10;---stdout---&#10;hello&#10;&#10;---errout---&#10;&#10;" T="mt:wstr" /><Param Name="KeywordName" Value="" T="mt:wstr" /><Param Name="TaskName" Value="" T="mt:wstr" /><Param Name="OSVersion" Value="" T="mt:wstr" /><Param Name="Operation" Value="RunScript" T="mt:wstr" /><Param Name="ContainerId" Value="" T="mt:wstr" /><Param Name="GAVersion" Value="" T="mt:wstr" /><Param Name="TenantName" Value="" T="mt:wstr" /><Param Name="Duration" Value="0" T="mt:uint64" /><Param Name="ExtensionType" Value="" T="mt:wstr" /></Data> \ No newline at end of file
diff --git a/tests/data/ext/sample_ext.zip b/tests/data/ext/sample_ext.zip
new file mode 100644
index 0000000..08cfaf7
--- /dev/null
+++ b/tests/data/ext/sample_ext.zip
Binary files differ
diff --git a/tests/data/ext/sample_ext/HandlerManifest.json b/tests/data/ext/sample_ext/HandlerManifest.json
new file mode 100644
index 0000000..9890d0c
--- /dev/null
+++ b/tests/data/ext/sample_ext/HandlerManifest.json
@@ -0,0 +1,14 @@
+[{
+ "name": "ExampleHandlerLinux",
+ "version": 1.0,
+ "handlerManifest": {
+ "installCommand": "sample.py -install",
+ "uninstallCommand": "sample.py -uninstall",
+ "updateCommand": "sample.py -update",
+ "enableCommand": "sample.py -enable",
+ "disableCommand": "sample.py -disable",
+ "rebootAfterInstall": false,
+ "reportHeartbeat": false
+ }
+}]
+
diff --git a/tests/data/ext/sample_ext/sample.py b/tests/data/ext/sample_ext/sample.py
new file mode 100755
index 0000000..7107ac2
--- /dev/null
+++ b/tests/data/ext/sample_ext/sample.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+
+import os
+
+def get_seq():
+ latest_seq = -1;
+ config_dir = os.path.join(os.getcwd(), "config")
+ if os.path.isdir(config_dir):
+ for item in os.listdir(config_dir):
+ item_path = os.path.join(config_dir, item)
+ if os.path.isfile(item_path):
+ seperator = item.rfind(".")
+ if seperator > 0 and item[seperator + 1:] == "settings":
+ seq = int(item[0: seperator])
+ if seq > latest_seq:
+ latest_seq = seq
+ return latest_seq
+
+
+succeed_status = """
+[{
+ "status": {
+ "status": "success"
+ }
+}]
+"""
+
+if __name__ == "__main__":
+ seq = get_seq()
+ if seq >= 0:
+ status_file = os.path.join(os.getcwd(), "status", "{0}.status".format(seq))
+ with open(status_file, "w+") as status:
+ status.write(succeed_status)
diff --git a/tests/data/metadata/certificates.json b/tests/data/metadata/certificates.json
new file mode 100644
index 0000000..4db7a06
--- /dev/null
+++ b/tests/data/metadata/certificates.json
@@ -0,0 +1,7 @@
+{
+ "certificates":[{
+ "name":"foo",
+ "thumbprint":"bar",
+ "certificateDataUri":"baz"
+ }]
+}
diff --git a/tests/data/metadata/ext_handler_pkgs.json b/tests/data/metadata/ext_handler_pkgs.json
new file mode 100644
index 0000000..869c949
--- /dev/null
+++ b/tests/data/metadata/ext_handler_pkgs.json
@@ -0,0 +1,10 @@
+{
+ "versions": [{
+ "version":"1.3.0.0",
+ "uris":[{
+ "uri":"http://localhost/foo1"
+ },{
+ "uri":"http://localhost/foo2"
+ }]
+ }]
+}
diff --git a/tests/data/metadata/ext_handlers.json b/tests/data/metadata/ext_handlers.json
new file mode 100644
index 0000000..68efc19
--- /dev/null
+++ b/tests/data/metadata/ext_handlers.json
@@ -0,0 +1,19 @@
+[{
+ "name":"foo",
+ "properties":{
+ "version":"1.3.0.0",
+ "upgradePolicy": "manual",
+ "state": "enabled",
+ "extensions":[{
+ "name":"baz",
+ "sequenceNumber":0,
+ "publicSettings":{
+ "commandToExecute": "echo 123",
+ "uris":[]
+ }
+ }]
+ },
+ "versionUris":[{
+ "uri":"http://ext_handler_pkgs/versionUri"
+ }]
+}]
diff --git a/tests/data/metadata/ext_handlers_no_ext.json b/tests/data/metadata/ext_handlers_no_ext.json
new file mode 100644
index 0000000..fe51488
--- /dev/null
+++ b/tests/data/metadata/ext_handlers_no_ext.json
@@ -0,0 +1 @@
+[]
diff --git a/tests/data/metadata/identity.json b/tests/data/metadata/identity.json
new file mode 100644
index 0000000..e6e2273
--- /dev/null
+++ b/tests/data/metadata/identity.json
@@ -0,0 +1,4 @@
+{
+ "vmName":"foo",
+ "subscriptionId":"bar"
+}
diff --git a/tests/data/ovf-env.xml b/tests/data/ovf-env.xml
new file mode 100644
index 0000000..fc94943
--- /dev/null
+++ b/tests/data/ovf-env.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Environment xmlns="http://schemas.dmtf.org/ovf/environment/1" xmlns:oe="http://schemas.dmtf.org/ovf/environment/1" xmlns:wa="http://schemas.microsoft.com/windowsazure" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <wa:ProvisioningSection>
+ <wa:Version>1.0</wa:Version>
+ <LinuxProvisioningConfigurationSet xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
+ <ConfigurationSetType>LinuxProvisioningConfiguration</ConfigurationSetType>
+ <HostName>HostName</HostName>
+ <UserName>UserName</UserName>
+ <UserPassword>UserPassword</UserPassword>
+ <DisableSshPasswordAuthentication>false</DisableSshPasswordAuthentication>
+ <SSH>
+ <PublicKeys>
+ <PublicKey>
+ <Fingerprint>EB0C0AB4B2D5FC35F2F0658D19F44C8283E2DD62</Fingerprint>
+ <Path>$HOME/UserName/.ssh/authorized_keys</Path>
+ <Value>ssh-rsa AAAANOTAREALKEY== foo@bar.local</Value>
+ </PublicKey>
+ </PublicKeys>
+ <KeyPairs>
+ <KeyPair>
+ <Fingerprint>EB0C0AB4B2D5FC35F2F0658D19F44C8283E2DD62</Fingerprint>
+ <Path>$HOME/UserName/.ssh/id_rsa</Path>
+ </KeyPair>
+ </KeyPairs>
+ </SSH>
+ <CustomData>CustomData</CustomData>
+ </LinuxProvisioningConfigurationSet>
+ </wa:ProvisioningSection>
+ </Environment>
diff --git a/tests/data/wire/certs.xml b/tests/data/wire/certs.xml
new file mode 100644
index 0000000..6717c30
--- /dev/null
+++ b/tests/data/wire/certs.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="utf-8"?>
+<CertificateFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="certificates10.xsd">
+ <Version>2012-11-30</Version>
+ <Incarnation>12</Incarnation>
+ <Format>Pkcs7BlobWithPfxContents</Format>
+ <Data>MIINswYJKoZIhvcNAQcDoIINpDCCDaACAQIxggEwMIIBLAIBAoAUvyL+x6GkZXog
+QNfsXRZAdD9lc7IwDQYJKoZIhvcNAQEBBQAEggEArhMPepD/RqwdPcHEVqvrdZid
+72vXrOCuacRBhwlCGrNlg8oI+vbqmT6CSv6thDpet31ALUzsI4uQHq1EVfV1+pXy
+NlYD1CKhBCoJxs2fSPU4rc8fv0qs5JAjnbtW7lhnrqFrXYcyBYjpURKfa9qMYBmj
+NdijN+1T4E5qjxPr7zK5Dalp7Cgp9P2diH4Nax2nixotfek3MrEFBaiiegDd+7tE
+ux685GWYPqB5Fn4OsDkkYOdb0OE2qzLRrnlCIiBCt8VubWH3kMEmSCxBwSJupmQ8
+sxCWk+sBPQ9gJSt2sIqfx/61F8Lpu6WzP+ZOnMLTUn2wLU/d1FN85HXmnQALzTCC
+DGUGCSqGSIb3DQEHATAUBggqhkiG9w0DBwQIbEcBfddWPv+AggxAAOAt/kCXiffe
+GeJG0P2K9Q18XZS6Rz7Xcz+Kp2PVgqHKRpPjjmB2ufsRO0pM4z/qkHT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ext_conf.xml b/tests/data/wire/ext_conf.xml
new file mode 100644
index 0000000..725271d
--- /dev/null
+++ b/tests/data/wire/ext_conf.xml
@@ -0,0 +1,46 @@
+<Extensions version="1.0.0.0" goalStateIncarnation="9"><GuestAgentExtension xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
+ <GAFamilies>
+ <GAFamily>
+ <Name>Win8</Name>
+ <Uris>
+ <Uri>http://rdfepirv2hknprdstr03.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr04.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr05.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr06.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr07.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr08.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr09.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr10.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr11.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr12.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://zrdfepirv2hk2prdstr01.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ </Uris>
+ </GAFamily>
+ <GAFamily>
+ <Name>Win7</Name>
+ <Uris>
+ <Uri>http://rdfepirv2hknprdstr03.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr04.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr05.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr06.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr07.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr08.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr09.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr10.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr11.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr12.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://zrdfepirv2hk2prdstr01.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ </Uris>
+ </GAFamily>
+ </GAFamilies>
+</GuestAgentExtension>
+<Plugins>
+ <Plugin name="OSTCExtensions.ExampleHandlerLinux" version="1.0" location="http://rdfepirv2hknprdstr03.blob.core.windows.net/b01058962be54ceca550a390fa5ff064/Microsoft.OSTCExtensions_ExampleHandlerLinux_asiaeast_manifest.xml" config="" state="enabled" autoUpgrade="false" failoverlocation="http://rdfepirv2hknprdstr04.blob.core.windows.net/b01058962be54ceca550a390fa5ff064/Microsoft.OSTCExtensions_ExampleHandlerLinux_asiaeast_manifest.xml" runAsStartupTask="false" isJson="true" />
+</Plugins>
+<PluginSettings>
+ <Plugin name="OSTCExtensions.ExampleHandlerLinux" version="1.0">
+ <RuntimeSettings seqNo="0">{"runtimeSettings":[{"handlerSettings":{"protectedSettingsCertThumbprint":"4037FBF5F1F3014F99B5D6C7799E9B20E6871CB3","protectedSettings":"MIICWgYJK","publicSettings":{"foo":"bar"}}}]}</RuntimeSettings>
+ </Plugin>
+</PluginSettings>
+<StatusUploadBlob>https://yuezhatest.blob.core.windows.net/vhds/test-cs12.test-cs12.test-cs12.status?sr=b&amp;sp=rw&amp;se=9999-01-01&amp;sk=key1&amp;sv=2014-02-14&amp;sig=hfRh7gzUE7sUtYwke78IOlZOrTRCYvkec4hGZ9zZzXo%3D</StatusUploadBlob></Extensions>
+
diff --git a/tests/data/wire/ext_conf_no_public.xml b/tests/data/wire/ext_conf_no_public.xml
new file mode 100644
index 0000000..abbde80
--- /dev/null
+++ b/tests/data/wire/ext_conf_no_public.xml
@@ -0,0 +1,46 @@
+<Extensions version="1.0.0.0" goalStateIncarnation="9"><GuestAgentExtension xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
+ <GAFamilies>
+ <GAFamily>
+ <Name>Win8</Name>
+ <Uris>
+ <Uri>http://rdfepirv2hknprdstr03.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr04.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr05.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr06.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr07.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr08.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr09.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr10.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr11.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr12.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://zrdfepirv2hk2prdstr01.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ </Uris>
+ </GAFamily>
+ <GAFamily>
+ <Name>Win7</Name>
+ <Uris>
+ <Uri>http://rdfepirv2hknprdstr03.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr04.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr05.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr06.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr07.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr08.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr09.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr10.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr11.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr12.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://zrdfepirv2hk2prdstr01.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ </Uris>
+ </GAFamily>
+ </GAFamilies>
+</GuestAgentExtension>
+<Plugins>
+ <Plugin name="OSTCExtensions.ExampleHandlerLinux" version="1.0" location="http://rdfepirv2hknprdstr03.blob.core.windows.net/b01058962be54ceca550a390fa5ff064/Microsoft.OSTCExtensions_ExampleHandlerLinux_asiaeast_manifest.xml" config="" state="enabled" autoUpgrade="false" failoverlocation="http://rdfepirv2hknprdstr04.blob.core.windows.net/b01058962be54ceca550a390fa5ff064/Microsoft.OSTCExtensions_ExampleHandlerLinux_asiaeast_manifest.xml" runAsStartupTask="false" isJson="true" />
+</Plugins>
+<PluginSettings>
+ <Plugin name="OSTCExtensions.ExampleHandlerLinux" version="1.0">
+ <RuntimeSettings seqNo="0">{"runtimeSettings":[{"handlerSettings":{"protectedSettingsCertThumbprint":"4037FBF5F1F3014F99B5D6C7799E9B20E6871CB3","protectedSettings":"MIICWgYJK"}}]}</RuntimeSettings>
+ </Plugin>
+</PluginSettings>
+<StatusUploadBlob>https://yuezhatest.blob.core.windows.net/vhds/test-cs12.test-cs12.test-cs12.status?sr=b&amp;sp=rw&amp;se=9999-01-01&amp;sk=key1&amp;sv=2014-02-14&amp;sig=hfRh7gzUE7sUtYwke78IOlZOrTRCYvkec4hGZ9zZzXo%3D</StatusUploadBlob></Extensions>
+
diff --git a/tests/data/wire/ext_conf_no_settings.xml b/tests/data/wire/ext_conf_no_settings.xml
new file mode 100644
index 0000000..df76d54
--- /dev/null
+++ b/tests/data/wire/ext_conf_no_settings.xml
@@ -0,0 +1,41 @@
+<Extensions version="1.0.0.0" goalStateIncarnation="9"><GuestAgentExtension xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
+ <GAFamilies>
+ <GAFamily>
+ <Name>Win8</Name>
+ <Uris>
+ <Uri>http://rdfepirv2hknprdstr03.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr04.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr05.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr06.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr07.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr08.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr09.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr10.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr11.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr12.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ <Uri>http://zrdfepirv2hk2prdstr01.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
+ </Uris>
+ </GAFamily>
+ <GAFamily>
+ <Name>Win7</Name>
+ <Uris>
+ <Uri>http://rdfepirv2hknprdstr03.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr04.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr05.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr06.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr07.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr08.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr09.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr10.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr11.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://rdfepirv2hknprdstr12.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ <Uri>http://zrdfepirv2hk2prdstr01.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
+ </Uris>
+ </GAFamily>
+ </GAFamilies>
+</GuestAgentExtension>
+<Plugins>
+ <Plugin name="OSTCExtensions.ExampleHandlerLinux" version="1.0" location="http://rdfepirv2hknprdstr03.blob.core.windows.net/b01058962be54ceca550a390fa5ff064/Microsoft.OSTCExtensions_ExampleHandlerLinux_asiaeast_manifest.xml" config="" state="enabled" autoUpgrade="false" failoverlocation="http://rdfepirv2hknprdstr04.blob.core.windows.net/b01058962be54ceca550a390fa5ff064/Microsoft.OSTCExtensions_ExampleHandlerLinux_asiaeast_manifest.xml" runAsStartupTask="false" isJson="true" />
+</Plugins>
+<StatusUploadBlob>https://yuezhatest.blob.core.windows.net/vhds/test-cs12.test-cs12.test-cs12.status?sr=b&amp;sp=rw&amp;se=9999-01-01&amp;sk=key1&amp;sv=2014-02-14&amp;sig=hfRh7gzUE7sUtYwke78IOlZOrTRCYvkec4hGZ9zZzXo%3D</StatusUploadBlob></Extensions>
+
diff --git a/tests/data/wire/goal_state.xml b/tests/data/wire/goal_state.xml
new file mode 100644
index 0000000..960444b
--- /dev/null
+++ b/tests/data/wire/goal_state.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<GoalState xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="goalstate10.xsd">
+ <Version>2010-12-15</Version>
+ <Incarnation>1</Incarnation>
+ <Machine>
+ <ExpectedState>Started</ExpectedState>
+ <LBProbePorts>
+ <Port>16001</Port>
+ </LBProbePorts>
+ </Machine>
+ <Container>
+ <ContainerId>c6d5526c-5ac2-4200-b6e2-56f2b70c5ab2</ContainerId>
+ <RoleInstanceList>
+ <RoleInstance>
+ <InstanceId>MachineRole_IN_0</InstanceId>
+ <State>Started</State>
+ <Configuration>
+ <HostingEnvironmentConfig>http://hostingenvuri/</HostingEnvironmentConfig>
+ <SharedConfig>http://sharedconfiguri/</SharedConfig>
+ <Certificates>http://certificatesuri/</Certificates>
+ <ExtensionsConfig>http://extensionsconfiguri/</ExtensionsConfig>
+ <FullConfig>http://fullconfiguri/</FullConfig>
+ </Configuration>
+ </RoleInstance>
+ </RoleInstanceList>
+ </Container>
+ </GoalState>
diff --git a/tests/data/wire/goal_state_no_ext.xml b/tests/data/wire/goal_state_no_ext.xml
new file mode 100644
index 0000000..0b4f566
--- /dev/null
+++ b/tests/data/wire/goal_state_no_ext.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<GoalState xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="goalstate10.xsd">
+ <Version>2010-12-15</Version>
+ <Incarnation>1</Incarnation>
+ <Machine>
+ <ExpectedState>Started</ExpectedState>
+ <LBProbePorts>
+ <Port>16001</Port>
+ </LBProbePorts>
+ </Machine>
+ <Container>
+ <ContainerId>c6d5526c-5ac2-4200-b6e2-56f2b70c5ab2</ContainerId>
+ <RoleInstanceList>
+ <RoleInstance>
+ <InstanceId>MachineRole_IN_0</InstanceId>
+ <State>Started</State>
+ <Configuration>
+ <HostingEnvironmentConfig>http://hostingenvuri/</HostingEnvironmentConfig>
+ <SharedConfig>http://sharedconfiguri/</SharedConfig>
+ <Certificates>http://certificatesuri/</Certificates>
+ <FullConfig>http://fullconfiguri/</FullConfig>
+ </Configuration>
+ </RoleInstance>
+ </RoleInstanceList>
+ </Container>
+ </GoalState>
diff --git a/tests/test_hostingenv.py b/tests/data/wire/hosting_env.xml
index 3d2ce73..f763a25 100644
--- a/tests/test_hostingenv.py
+++ b/tests/data/wire/hosting_env.xml
@@ -1,32 +1,4 @@
-# Copyright 2014 Microsoft Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# Requires Python 2.4+ and Openssl 1.0+
-#
-# Implements parts of RFC 2131, 1541, 1497 and
-# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
-# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-
-import tests.env
-import tests.tools as tools
-import uuid
-import unittest
-import os
-import azurelinuxagent.protocol.v1 as v1
-
-hosting_env_sample=u"""
- <HostingEnvironmentConfig version="1.0.0.0" goalStateIncarnation="1">
+<HostingEnvironmentConfig version="1.0.0.0" goalStateIncarnation="1">
<StoredCertificates>
<StoredCertificate name="Stored0Microsoft.WindowsAzure.Plugins.RemoteAccess.PasswordEncryption" certificateId="sha1:C093FA5CD3AAE057CB7C4E04532B2E16E07C26CA" storeName="My" configurationLevel="System" />
</StoredCertificates>
@@ -50,17 +22,3 @@ hosting_env_sample=u"""
<Resource name="DiagnosticStore" type="directory" request="Microsoft.Cis.Fabric.Controller.Descriptions.ServiceDescription.Data.Policy" sticky="true" size="1" path="db00a7755a5e4e8a8fe4b19bc3b330c3.MachineRole.DiagnosticStore\" disableQuota="false" />
</ResourceReferences>
</HostingEnvironmentConfig>
-"""
-
-class TestHostingEvn(unittest.TestCase):
- def test_hosting_env(self):
- hosting_env = v1.HostingEnv(hosting_env_sample)
- self.assertNotEquals(None, hosting_env)
- self.assertEquals("MachineRole_IN_0", hosting_env.vm_name)
- self.assertEquals("MachineRole", hosting_env.role_name)
- self.assertEquals("db00a7755a5e4e8a8fe4b19bc3b330c3",
- hosting_env.deployment_name)
-
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/data/wire/manifest.xml b/tests/data/wire/manifest.xml
new file mode 100644
index 0000000..943755a
--- /dev/null
+++ b/tests/data/wire/manifest.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<PluginVersionManifest xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
+ <Plugins>
+ <Plugin>
+ <Version>1.0</Version>
+ <Uris>
+ <Uri>http://foo.bar/zar/OSTCExtensions.ExampleHandlerLinux</Uri>
+ </Uris>
+ </Plugin>
+ <Plugin>
+ <Version>1.1</Version>
+ <Uris>
+ <Uri>http://foo.bar/zar/OSTCExtensions.ExampleHandlerLinux</Uri>
+ </Uris>
+ </Plugin>
+ </Plugins>
+</PluginVersionManifest>
+
diff --git a/tests/test_sharedconfig.py b/tests/data/wire/shared_config.xml
index f480253..7c6ae14 100644
--- a/tests/test_sharedconfig.py
+++ b/tests/data/wire/shared_config.xml
@@ -1,33 +1,4 @@
-# Copyright 2014 Microsoft Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# Requires Python 2.4+ and Openssl 1.0+
-#
-# Implements parts of RFC 2131, 1541, 1497 and
-# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
-# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-
-import tests.env
-import tests.tools as tools
-import uuid
-import unittest
-import os
-import azurelinuxagent.protocol.v1 as v1
-
-shared_config_sample=u"""
-
- <SharedConfig version="1.0.0.0" goalStateIncarnation="1">
+<SharedConfig version="1.0.0.0" goalStateIncarnation="1">
<Deployment name="db00a7755a5e4e8a8fe4b19bc3b330c3" guid="{ce5a036f-5c93-40e7-8adf-2613631008ab}" incarnation="2">
<Service name="MyVMRoleService" guid="{00000000-0000-0000-0000-000000000000}" />
<ServiceInstance name="db00a7755a5e4e8a8fe4b19bc3b330c3.1" guid="{d113f4d7-9ead-4e73-b715-b724b5b7842c}" />
@@ -69,11 +40,3 @@ shared_config_sample=u"""
</Instance>
</Instances>
</SharedConfig>
-"""
-
-class TestSharedConfig(unittest.TestCase):
- def test_sharedconfig(self):
- shared_conf = v1.SharedConfig(shared_config_sample)
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/sshd_config b/tests/data/wire/sshd_config
index 77fb290..77fb290 100644
--- a/tests/sshd_config
+++ b/tests/data/wire/sshd_config
diff --git a/tests/data/wire/trans_cert b/tests/data/wire/trans_cert
new file mode 100644
index 0000000..d560ae2
--- /dev/null
+++ b/tests/data/wire/trans_cert
@@ -0,0 +1,19 @@
+-----BEGIN CERTIFICATE-----
+MIIDBzCCAe+gAwIBAgIJANujJuVt5eC8MA0GCSqGSIb3DQEBCwUAMBkxFzAVBgNV
+BAMMDkxpbnV4VHJhbnNwb3J0MCAXDTE0MTAyNDA3MjgwN1oYDzIxMDQwNzEyMDcy
+ODA3WjAZMRcwFQYDVQQDDA5MaW51eFRyYW5zcG9ydDCCASIwDQYJKoZIhvcNAQEB
+BQADggEPADCCAQoCggEBANPcJAkd6V5NeogSKjIeTXOWC5xzKTyuJPt4YZMVSosU
+0lI6a0wHp+g2fP22zrVswW+QJz6AVWojIEqLQup3WyCXZTv8RUblHnIjkvX/+J/G
+aLmz0G5JzZIpELL2C8IfQLH2IiPlK9LOQH00W74WFcK3QqcJ6Kw8GcVaeSXT1r7X
+QcGMqEjcWJkpKLoMJv3LMufE+JMdbXDUGY+Ps7Zicu8KXvBPaKVsc6H2jrqBS8et
+jXbzLyrezTUDz45rmyRJzCO5Sk2pohuYg73wUykAUPVxd7L8WnSyqz1v4zrObqnw
+BAyor67JR/hjTBfjFOvd8qFGonfiv2Vnz9XsYFTZsXECAwEAAaNQME4wHQYDVR0O
+BBYEFL8i/sehpGV6IEDX7F0WQHQ/ZXOyMB8GA1UdIwQYMBaAFL8i/sehpGV6IEDX
+7F0WQHQ/ZXOyMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAMPLrimT
+Gptu5pLRHPT8OFRN+skNSkepYaUaJuq6cSKxLumSYkD8++rohu+1+a7t1YNjjNSJ
+8ohRAynRJ7aRqwBmyX2OPLRpOfyRZwR0rcFfAMORm/jOE6WBdqgYD2L2b+tZplGt
+/QqgQzebaekXh/032FK4c74Zg5r3R3tfNSUMG6nLauWzYHbQ5SCdkuQwV0ehGqh5
+VF1AOdmz4CC2237BNznDFQhkeU0LrqqAoE/hv5ih7klJKZdS88rOYEnVJsFFJb0g
+qaycXjOm5Khgl4hKrd+DBD/qj4IVVzsmdpFli72k6WLBHGOXusUGo/3isci2iAIt
+DsfY6XGSEIhZnA4=
+-----END CERTIFICATE-----
diff --git a/tests/data/wire/trans_prv b/tests/data/wire/trans_prv
new file mode 100644
index 0000000..063cf15
--- /dev/null
+++ b/tests/data/wire/trans_prv
@@ -0,0 +1,28 @@
+-----BEGIN PRIVATE KEY-----
+MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDT3CQJHeleTXqI
+EioyHk1zlguccyk8riT7eGGTFUqLFNJSOmtMB6foNnz9ts61bMFvkCc+gFVqIyBK
+i0Lqd1sgl2U7/EVG5R5yI5L1//ifxmi5s9BuSc2SKRCy9gvCH0Cx9iIj5SvSzkB9
+NFu+FhXCt0KnCeisPBnFWnkl09a+10HBjKhI3FiZKSi6DCb9yzLnxPiTHW1w1BmP
+j7O2YnLvCl7wT2ilbHOh9o66gUvHrY128y8q3s01A8+Oa5skScwjuUpNqaIbmIO9
+8FMpAFD1cXey/Fp0sqs9b+M6zm6p8AQMqK+uyUf4Y0wX4xTr3fKhRqJ34r9lZ8/V
+7GBU2bFxAgMBAAECggEBAM4hsfog3VAAyIieS+npq+gbhH6bWfMNaTQ3g5CNNbMu
+9hhFeOJHzKnWYjSlamgBQhAfTN+2E+Up+iAtcVUZ/lMumrQLlwgMo1vgmvu5Kxmh
+/YE5oEG+k0JzrCjD1trwd4zvc3ZDYyk/vmVTzTOc311N248UyArUiyqHBbq1a4rP
+tJhCLn2c4S7flXGF0MDVGZyV9V7J8N8leq/dRGMB027Li21T+B4mPHXa6b8tpRPL
+4vc8sHoUJDa2/+mFDJ2XbZfmlgd3MmIPlRn1VWoW7mxgT/AObsPl7LuQx7+t80Wx
+hIMjuKUHRACQSLwHxJ3SQRFWp4xbztnXSRXYuHTscLUCgYEA//Uu0qIm/FgC45yG
+nXtoax4+7UXhxrsWDEkbtL6RQ0TSTiwaaI6RSQcjrKDVSo/xo4ZySTYcRgp5GKlI
+CrWyNM+UnIzTNbZOtvSIAfjxYxMsq1vwpTlOB5/g+cMukeGg39yUlrjVNoFpv4i6
+9t4yYuEaF4Vww0FDd2nNKhhW648CgYEA0+UYH6TKu03zDXqFpwf4DP2VoSo8OgfQ
+eN93lpFNyjrfzvxDZkGF+7M/ebyYuI6hFplVMu6BpgpFP7UVJpW0Hn/sXkTq7F1Q
+rTJTtkTp2+uxQVP/PzSOqK0Twi5ifkfoEOkPkNNtTiXzwCW6Qmmcvln2u893pyR5
+gqo5BHR7Ev8CgYAb7bXpN9ZHLJdMHLU3k9Kl9YvqOfjTxXA3cPa79xtEmsrTys4q
+4HuL22KSII6Fb0VvkWkBAg19uwDRpw78VC0YxBm0J02Yi8b1AaOhi3dTVzFFlWeh
+r6oK/PAAcMKxGkyCgMAZ3hstsltGkfXMoBwhW+yL6nyOYZ2p9vpzAGrjkwKBgQDF
+0huzbyXVt/AxpTEhv07U0enfjI6tnp4COp5q8zyskEph8yD5VjK/yZh5DpmFs6Kw
+dnYUFpbzbKM51tToMNr3nnYNjEnGYVfwWgvNHok1x9S0KLcjSu3ki7DmmGdbfcYq
+A2uEyd5CFyx5Nr+tQOwUyeiPbiFG6caHNmQExLoiAQKBgFPy9H8///xsadYmZ18k
+r77R2CvU7ArxlLfp9dr19aGYKvHvnpsY6EuChkWfy8Xjqn3ogzgrHz/rn3mlGUpK
+vbtwtsknAHtTbotXJwfaBZv2RGgGRr3DzNo6ll2Aez0lNblZFXq132h7+y5iLvar
+4euORaD/fuM4UPlR5mN+bypU
+-----END PRIVATE KEY-----
diff --git a/tests/data/wire/version_info.xml b/tests/data/wire/version_info.xml
new file mode 100644
index 0000000..b4d0a3f
--- /dev/null
+++ b/tests/data/wire/version_info.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Versions>
+ <Preferred>
+ <Version>2012-11-30</Version>
+ </Preferred>
+ <Supported>
+ <Version>2010-12-15</Version>
+ <Version>2010-28-10</Version>
+ </Supported>
+</Versions>
diff --git a/tests/env.py b/tests/distro/__init__.py
index 5bc6eb8..9bdb27e 100644
--- a/tests/env.py
+++ b/tests/distro/__init__.py
@@ -17,10 +17,3 @@
# Implements parts of RFC 2131, 1541, 1497 and
# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-
-import os
-import sys
-
-test_root = os.path.dirname(os.path.abspath(__file__))
-project_root = os.path.dirname(test_root)
-sys.path.insert(0, project_root)
diff --git a/tests/distro/test_daemon.py b/tests/distro/test_daemon.py
new file mode 100644
index 0000000..9d3c45b
--- /dev/null
+++ b/tests/distro/test_daemon.py
@@ -0,0 +1,65 @@
+# Copyright 2014 Microsoft Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Requires Python 2.4+ and Openssl 1.0+
+#
+# Implements parts of RFC 2131, 1541, 1497 and
+# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
+# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
+
+from tests.tools import *
+from azurelinuxagent.distro.loader import get_distro
+from azurelinuxagent.exception import *
+from azurelinuxagent.distro.default.daemon import *
+
+class MockDaemonCall(object):
+ def __init__(self, daemon_handler, count):
+ self.daemon_handler = daemon_handler
+ self.count = count
+
+ def __call__(self, *args, **kw):
+ self.count = self.count - 1
+ #Stop daemon after restarting for n times
+ if self.count <= 0:
+ self.daemon_handler.running = False
+ raise Exception("Mock unhandled exception")
+
+@patch("time.sleep")
+class TestDaemon(AgentTestCase):
+ def test_daemon_restart(self, mock_sleep):
+ distro = get_distro()
+ mock_daemon = Mock(side_effect=MockDaemonCall(distro.daemon_handler, 2))
+ distro.daemon_handler.daemon = mock_daemon
+ distro.daemon_handler.check_pid = Mock()
+ distro.daemon_handler.run()
+
+ mock_sleep.assert_any_call(15)
+ self.assertEquals(2, distro.daemon_handler.daemon.call_count)
+
+ @patch("azurelinuxagent.distro.default.daemon.conf")
+ @patch("azurelinuxagent.distro.default.daemon.sys.exit")
+ def test_check_pid(self, mock_exit, mock_conf, mock_sleep):
+ distro = get_distro()
+ mock_pid_file = os.path.join(self.tmp_dir, "pid")
+ mock_conf.get_agent_pid_file_path = Mock(return_value=mock_pid_file)
+
+ distro.daemon_handler.check_pid()
+ self.assertTrue(os.path.isfile(mock_pid_file))
+
+ distro.daemon_handler.check_pid()
+ mock_exit.assert_any_call(0)
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/tests/distro/test_extension.py b/tests/distro/test_extension.py
new file mode 100644
index 0000000..d0b631f
--- /dev/null
+++ b/tests/distro/test_extension.py
@@ -0,0 +1,191 @@
+# Copyright 2014 Microsoft Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Requires Python 2.4+ and Openssl 1.0+
+#
+# Implements parts of RFC 2131, 1541, 1497 and
+# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
+# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
+
+from tests.tools import *
+from tests.protocol.mockwiredata import *
+from azurelinuxagent.exception import *
+from azurelinuxagent.distro.loader import get_distro
+from azurelinuxagent.protocol.restapi import get_properties
+from azurelinuxagent.protocol.wire import WireProtocol
+
+@patch("time.sleep")
+@patch("azurelinuxagent.protocol.wire.CryptUtil")
+@patch("azurelinuxagent.utils.restutil.http_get")
+class TestExtension(AgentTestCase):
+
+ def _assert_handler_status(self, report_vm_status, expected_status,
+ expected_ext_count, version):
+ self.assertTrue(report_vm_status.called)
+ args, kw = report_vm_status.call_args
+ vm_status = args[0]
+ self.assertNotEquals(0, len(vm_status.vmAgent.extensionHandlers))
+ handler_status = vm_status.vmAgent.extensionHandlers[0]
+ self.assertEquals(expected_status, handler_status.status)
+ self.assertEquals("OSTCExtensions.ExampleHandlerLinux",
+ handler_status.name)
+ self.assertEquals(version, handler_status.version)
+ self.assertEquals(expected_ext_count, len(handler_status.extensions))
+
+ def _assert_no_handler_status(self, report_vm_status):
+ self.assertTrue(report_vm_status.called)
+ args, kw = report_vm_status.call_args
+ vm_status = args[0]
+ self.assertEquals(0, len(vm_status.vmAgent.extensionHandlers))
+
+ def _create_mock(self, test_data, mock_http_get, MockCryptUtil, _):
+ """Test enable/disable/unistall of an extension"""
+ distro = get_distro()
+
+ #Mock protocol to return test data
+ mock_http_get.side_effect = test_data.mock_http_get
+ MockCryptUtil.side_effect = test_data.mock_crypt_util
+
+ protocol = WireProtocol("foo.bar")
+ protocol.detect()
+ protocol.report_ext_status = MagicMock()
+ protocol.report_vm_status = MagicMock()
+ distro.protocol_util.get_protocol = Mock(return_value=protocol)
+
+ return distro, protocol
+
+ def test_ext_handler(self, *args):
+ test_data = WireProtocolData(DATA_FILE)
+ distro, protocol = self._create_mock(test_data, *args)
+
+ #Test enable scenario.
+ distro.ext_handlers_handler.run()
+ self._assert_handler_status(protocol.report_vm_status, "Ready", 1, "1.0")
+ self._assert_ext_status(protocol.report_ext_status, "success", 0)
+
+ #Test goal state not changed
+ distro.ext_handlers_handler.run()
+ self._assert_handler_status(protocol.report_vm_status, "Ready", 1, "1.0")
+
+ #Test goal state changed
+ test_data.goal_state = test_data.goal_state.replace("<Incarnation>1<",
+ "<Incarnation>2<")
+ test_data.ext_conf = test_data.ext_conf.replace("seqNo=\"0\"",
+ "seqNo=\"1\"")
+ distro.ext_handlers_handler.run()
+ self._assert_handler_status(protocol.report_vm_status, "Ready", 1, "1.0")
+ self._assert_ext_status(protocol.report_ext_status, "success", 1)
+
+ #Test upgrade
+ test_data.goal_state = test_data.goal_state.replace("<Incarnation>2<",
+ "<Incarnation>3<")
+ test_data.ext_conf = test_data.ext_conf.replace("1.0", "1.1")
+ test_data.ext_conf = test_data.ext_conf.replace("seqNo=\"1\"",
+ "seqNo=\"2\"")
+ distro.ext_handlers_handler.run()
+ self._assert_handler_status(protocol.report_vm_status, "Ready", 1, "1.1")
+ self._assert_ext_status(protocol.report_ext_status, "success", 2)
+
+ #Test disable
+ test_data.goal_state = test_data.goal_state.replace("<Incarnation>3<",
+ "<Incarnation>4<")
+ test_data.ext_conf = test_data.ext_conf.replace("enabled", "disabled")
+ distro.ext_handlers_handler.run()
+ self._assert_handler_status(protocol.report_vm_status, "NotReady",
+ 1, "1.1")
+
+ #Test uninstall
+ test_data.goal_state = test_data.goal_state.replace("<Incarnation>4<",
+ "<Incarnation>5<")
+ test_data.ext_conf = test_data.ext_conf.replace("disabled", "uninstall")
+ distro.ext_handlers_handler.run()
+ self._assert_no_handler_status(protocol.report_vm_status)
+
+ #Test uninstall again!
+ test_data.goal_state = test_data.goal_state.replace("<Incarnation>5<",
+ "<Incarnation>6<")
+ distro.ext_handlers_handler.run()
+ self._assert_no_handler_status(protocol.report_vm_status)
+
+ def test_ext_handler_no_settings(self, *args):
+ test_data = WireProtocolData(DATA_FILE_EXT_NO_SETTINGS)
+ distro, protocol = self._create_mock(test_data, *args)
+
+ distro.ext_handlers_handler.run()
+ self._assert_handler_status(protocol.report_vm_status, "Ready", 0, "1.0")
+
+ def test_ext_handler_no_public_settings(self, *args):
+ test_data = WireProtocolData(DATA_FILE_EXT_NO_PUBLIC)
+ distro, protocol = self._create_mock(test_data, *args)
+
+ distro.ext_handlers_handler.run()
+ self._assert_handler_status(protocol.report_vm_status, "Ready", 1, "1.0")
+
+ def test_ext_handler_no_ext(self, *args):
+ test_data = WireProtocolData(DATA_FILE_NO_EXT)
+ distro, protocol = self._create_mock(test_data, *args)
+
+ #Assert no extension handler status
+ distro.ext_handlers_handler.run()
+ self._assert_no_handler_status(protocol.report_vm_status)
+
+ @patch('azurelinuxagent.distro.default.extension.add_event')
+ def test_ext_handler_download_failure(self, mock_add_event, *args):
+ test_data = WireProtocolData(DATA_FILE)
+ distro, protocol = self._create_mock(test_data, *args)
+ protocol.download_ext_handler_pkg = Mock(side_effect=ProtocolError)
+
+ distro.ext_handlers_handler.run()
+ args, kw = mock_add_event.call_args
+ self.assertEquals(False, kw['is_success'])
+ self.assertEquals("OSTCExtensions.ExampleHandlerLinux", kw['name'])
+ self.assertEquals("Download", kw['op'])
+
+ @patch('azurelinuxagent.distro.default.extension.fileutil')
+ def test_ext_handler_io_error(self, mock_fileutil, *args):
+ test_data = WireProtocolData(DATA_FILE)
+ distro, protocol = self._create_mock(test_data, *args)
+
+ mock_fileutil.write_file.return_value = IOError("Mock IO Error")
+ distro.ext_handlers_handler.run()
+
+ def _assert_ext_status(self, report_ext_status, expected_status,
+ expected_seq_no):
+ self.assertTrue(report_ext_status.called)
+ args, kw = report_ext_status.call_args
+ ext_status = args[-1]
+ self.assertEquals(expected_status, ext_status.status)
+ self.assertEquals(expected_seq_no, ext_status.sequenceNumber)
+
+ def test_ext_handler_no_reporting_status(self, *args):
+ test_data = WireProtocolData(DATA_FILE)
+ distro, protocol = self._create_mock(test_data, *args)
+ distro.ext_handlers_handler.run()
+ self._assert_handler_status(protocol.report_vm_status, "Ready", 1, "1.0")
+
+ #Remove status file and re-run collecting extension status
+ status_file = os.path.join(self.tmp_dir,
+ "OSTCExtensions.ExampleHandlerLinux-1.0",
+ "status", "0.status")
+ self.assertTrue(os.path.isfile(status_file))
+ os.remove(status_file)
+
+ distro.ext_handlers_handler.run()
+ self._assert_handler_status(protocol.report_vm_status, "Ready", 1, "1.0")
+ self._assert_ext_status(protocol.report_ext_status, "error", 0)
+
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/tests/test_future.py b/tests/distro/test_loader.py
index 20edc93..94ca913 100644
--- a/tests/test_future.py
+++ b/tests/distro/test_loader.py
@@ -18,20 +18,19 @@
# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-import tests.env
from tests.tools import *
-import uuid
-import unittest
-import os
-import shutil
-import time
-import azurelinuxagent.future as future
+from azurelinuxagent.distro.loader import get_distro
+from azurelinuxagent.distro.default.distro import DefaultDistro
-class TestFuture(unittest.TestCase):
- def test_future_pkgs(self):
- future.httpclient
- future.urlparse
- future.text(b"asdf", encoding="utf-8")
+class TestDistroLoader(AgentTestCase):
+
+ @distros()
+ def test_distro_loader(self, *distro_args):
+ distro = get_distro(*distro_args)
+ self.assertNotEquals(None, distro)
+ self.assertNotEquals(DefaultDistro, type(distro))
+
if __name__ == '__main__':
unittest.main()
+
diff --git a/tests/test_protocolFactory.py b/tests/distro/test_monitor.py
index 9928b88..1dd7740 100644
--- a/tests/test_protocolFactory.py
+++ b/tests/distro/test_monitor.py
@@ -18,20 +18,15 @@
# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-import tests.env
from tests.tools import *
-import uuid
-import unittest
-import os
-import azurelinuxagent.protocol as protocol
-import azurelinuxagent.protocol.protocolFactory as protocolFactory
+from azurelinuxagent.exception import *
+from azurelinuxagent.distro.default.monitor import *
-class TestWireProtocolEndpoint(unittest.TestCase):
- def test_get_available_protocols(self):
- mockGetV1 = MockFunc(retval="Mock protocol")
- protocols = protocolFactory.get_available_protocols([mockGetV1])
- self.assertNotEquals(None, protocols)
- self.assertNotEquals(0, len(protocols))
+class TestMonitor(AgentTestCase):
+ def test_parse_xml_event(self):
+ data_str = load_data('ext/event.xml')
+ event = parse_xml_event(data_str)
+ self.assertNotEquals(None, event)
+ self.assertNotEquals(0, event.parameters)
+ self.assertNotEquals(None, event.parameters[0])
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/distro/test_protocol_util.py b/tests/distro/test_protocol_util.py
new file mode 100644
index 0000000..61339f3
--- /dev/null
+++ b/tests/distro/test_protocol_util.py
@@ -0,0 +1,89 @@
+# Copyright 2014 Microsoft Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Requires Python 2.4+ and Openssl 1.0+
+#
+# Implements parts of RFC 2131, 1541, 1497 and
+# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
+# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
+
+from tests.tools import *
+from azurelinuxagent.distro.loader import get_distro
+from azurelinuxagent.exception import *
+from azurelinuxagent.distro.default.protocolUtil import *
+
+@patch("time.sleep")
+class TestProtocolUtil(AgentTestCase):
+
+ @distros()
+ @patch("azurelinuxagent.distro.default.protocolUtil.MetadataProtocol")
+ @patch("azurelinuxagent.distro.default.protocolUtil.WireProtocol")
+ def test_detect_protocol(self, distro_name, distro_version, distro_full_name,
+ WireProtocol, MetadataProtocol, _, *distro_args):
+
+ WireProtocol.return_value = MagicMock()
+ MetadataProtocol.return_value = MagicMock()
+
+ distro = get_distro(distro_name, distro_version, distro_full_name)
+ distro.dhcp_handler = MagicMock()
+ distro.dhcp_handler.endpoint = "foo.bar"
+
+ #Test wire protocol is available
+ protocol = distro.protocol_util.detect_protocol()
+ self.assertEquals(WireProtocol.return_value, protocol)
+
+ #Test wire protocol is not available
+ distro.protocol_util.protocol = None
+ WireProtocol.side_effect = ProtocolError()
+
+ protocol = distro.protocol_util.detect_protocol()
+ self.assertEquals(MetadataProtocol.return_value, protocol)
+
+ #Test no protocol is available
+ distro.protocol_util.protocol = None
+ WireProtocol.side_effect = ProtocolError()
+ MetadataProtocol.side_effect = ProtocolError()
+ self.assertRaises(ProtocolError, distro.protocol_util.detect_protocol)
+
+ @distros()
+ def test_detect_protocol_by_file(self, distro_name, distro_version,
+ distro_full_name, _):
+ distro = get_distro(distro_name, distro_version, distro_full_name)
+ protocol_util = distro.protocol_util
+
+ protocol_util._detect_wire_protocol = Mock()
+ protocol_util._detect_metadata_protocol = Mock()
+
+ tag_file = os.path.join(self.tmp_dir, TAG_FILE_NAME)
+
+ #Test tag file doesn't exist
+ protocol_util.detect_protocol_by_file()
+ protocol_util._detect_wire_protocol.assert_any_call()
+ protocol_util._detect_metadata_protocol.assert_not_called()
+
+ #Test tag file exists
+ protocol_util.protocol = None
+ protocol_util._detect_wire_protocol.reset_mock()
+ protocol_util._detect_metadata_protocol.reset_mock()
+ with open(tag_file, "w+") as tag_fd:
+ tag_fd.write("")
+
+ protocol_util.detect_protocol_by_file()
+ protocol_util._detect_metadata_protocol.assert_any_call()
+ protocol_util._detect_wire_protocol.assert_not_called()
+
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/tests/test_agent.py b/tests/distro/test_provision.py
index 721b9f0..60249ce 100644
--- a/tests/test_agent.py
+++ b/tests/distro/test_provision.py
@@ -18,28 +18,30 @@
# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-import tests.env
-import tests.tools as tools
-import uuid
-import unittest
-import os
-import json
+from tests.tools import *
+from azurelinuxagent.distro.loader import get_distro
+from azurelinuxagent.distro.default.protocolUtil import *
import azurelinuxagent.utils.fileutil as fileutil
-import azurelinuxagent.agent as agent
-class TestAgent(unittest.TestCase):
- def test_parse_args(self):
- cmd, force, verbose = agent.parse_args(["deprovision+user",
- "-force",
- "/verbose"])
- self.assertEquals("deprovision+user", cmd)
- self.assertTrue(force)
- self.assertTrue(verbose)
+class TestProvision(AgentTestCase):
- cmd, force, verbose = agent.parse_args(["wrong cmd"])
- self.assertEquals("help", cmd)
- self.assertFalse(force)
- self.assertFalse(verbose)
+ @distros("redhat")
+ def test_provision(self, distro_name, distro_version, distro_full_name):
+ distro = get_distro(distro_name, distro_version, distro_full_name)
+ distro.osutil = MagicMock()
+ distro.osutil.decode_customdata = Mock(return_value="")
+
+ distro.protocol_util.detect_protocol_by_file = MagicMock()
+ distro.protocol_util.get_protocol = MagicMock()
+ conf.get_dvd_mount_point = Mock(return_value=self.tmp_dir)
+
+ ovfenv_file = os.path.join(self.tmp_dir, OVF_FILE_NAME)
+ ovfenv_data = load_data("ovf-env.xml")
+ fileutil.write_file(ovfenv_file, ovfenv_data)
+
+ handler = distro.provision_handler
+ handler.run()
if __name__ == '__main__':
unittest.main()
+
diff --git a/tests/run_all.sh b/tests/protocol/__init__.py
index 9e88c46..9bdb27e 100755..100644
--- a/tests/run_all.sh
+++ b/tests/protocol/__init__.py
@@ -1,7 +1,3 @@
-#!/bin/bash
-#
-# This script is used to set up a test env for extensions
-#
# Copyright 2014 Microsoft Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,20 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-
-script=$(dirname $0)
-root=$script
-cd $root
-root=`pwd`
-
-echo "Run unit test:"
-tests=`ls test_*.py | sed -e 's/\.py//'`
-for test in $tests ; do
- echo $test
-done
-
-if [ "$1" == "-c" ] ; then
- echo $tests | xargs coverage run -m unittest
-else
- echo $tests | xargs python -m unittest
-fi
+# Requires Python 2.4+ and Openssl 1.0+
+#
+# Implements parts of RFC 2131, 1541, 1497 and
+# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
+# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
diff --git a/tests/protocol/mockmetadata.py b/tests/protocol/mockmetadata.py
new file mode 100644
index 0000000..0f7b568
--- /dev/null
+++ b/tests/protocol/mockmetadata.py
@@ -0,0 +1,61 @@
+# Copyright 2014 Microsoft Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Requires Python 2.4+ and Openssl 1.0+
+#
+# Implements parts of RFC 2131, 1541, 1497 and
+# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
+# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
+
+from tests.tools import *
+from azurelinuxagent.future import httpclient
+from azurelinuxagent.utils.cryptutil import CryptUtil
+
+DATA_FILE = {
+ "identity": "metadata/identity.json",
+ "certificates": "metadata/certificates.json",
+ "ext_handlers": "metadata/ext_handlers.json",
+ "ext_handler_pkgs": "metadata/ext_handler_pkgs.json",
+}
+
+DATA_FILE_NO_EXT = DATA_FILE.copy()
+DATA_FILE_NO_EXT["ext_handlers"] = "metadata/ext_handlers_no_ext.json"
+
+class MetadataProtocolData(object):
+ def __init__(self, data_files):
+ self.identity = load_data(data_files.get("identity"))
+ self.certificates = load_data(data_files.get("certificates"))
+ self.ext_handlers = load_data(data_files.get("ext_handlers"))
+ self.ext_handler_pkgs = load_data(data_files.get("ext_handler_pkgs"))
+
+ def mock_http_get(self, url, *args, **kwargs):
+ content = None
+ if url.count(u"identity?") > 0:
+ content = self.identity
+ elif url.count(u"certificates") > 0:
+ content = self.certificates
+ elif url.count(u"extensionHandlers") > 0:
+ content = self.ext_handlers
+ elif url.count(u"versionUri") > 0:
+ content = self.ext_handler_pkgs
+ else:
+ raise Exception("Bad url {0}".format(url))
+ resp = MagicMock()
+ resp.status = httpclient.OK
+ if content is None:
+ resp.read = Mock(return_value=None)
+ else:
+ resp.read = Mock(return_value=content.encode("utf-8"))
+ return resp
+
diff --git a/tests/protocol/mockwiredata.py b/tests/protocol/mockwiredata.py
new file mode 100644
index 0000000..6ffd19c
--- /dev/null
+++ b/tests/protocol/mockwiredata.py
@@ -0,0 +1,101 @@
+# Copyright 2014 Microsoft Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Requires Python 2.4+ and Openssl 1.0+
+#
+# Implements parts of RFC 2131, 1541, 1497 and
+# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
+# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
+
+from tests.tools import *
+from azurelinuxagent.future import httpclient
+from azurelinuxagent.utils.cryptutil import CryptUtil
+
+DATA_FILE = {
+ "version_info": "wire/version_info.xml",
+ "goal_state": "wire/goal_state.xml",
+ "hosting_env": "wire/hosting_env.xml",
+ "shared_config": "wire/shared_config.xml",
+ "certs": "wire/certs.xml",
+ "ext_conf": "wire/ext_conf.xml",
+ "manifest": "wire/manifest.xml",
+ "trans_prv": "wire/trans_prv",
+ "trans_cert": "wire/trans_cert",
+ "test_ext": "ext/sample_ext.zip"
+}
+
+DATA_FILE_NO_EXT = DATA_FILE.copy()
+DATA_FILE_NO_EXT["goal_state"] = "wire/goal_state_no_ext.xml"
+
+DATA_FILE_EXT_NO_SETTINGS = DATA_FILE.copy()
+DATA_FILE_EXT_NO_SETTINGS["ext_conf"] = "wire/ext_conf_no_settings.xml"
+
+DATA_FILE_EXT_NO_PUBLIC = DATA_FILE.copy()
+DATA_FILE_EXT_NO_PUBLIC["ext_conf"] = "wire/ext_conf_no_public.xml"
+
+class WireProtocolData(object):
+ def __init__(self, data_files=DATA_FILE):
+ self.version_info = load_data(data_files.get("version_info"))
+ self.goal_state = load_data(data_files.get("goal_state"))
+ self.hosting_env = load_data(data_files.get("hosting_env"))
+ self.shared_config = load_data(data_files.get("shared_config"))
+ self.certs = load_data(data_files.get("certs"))
+ self.ext_conf = load_data(data_files.get("ext_conf"))
+ self.manifest = load_data(data_files.get("manifest"))
+ self.trans_prv = load_data(data_files.get("trans_prv"))
+ self.trans_cert = load_data(data_files.get("trans_cert"))
+ self.ext = load_bin_data(data_files.get("test_ext"))
+
+ def mock_http_get(self, url, *args, **kwargs):
+ content = None
+ if "versions" in url:
+ content = self.version_info
+ elif "goalstate" in url:
+ content = self.goal_state
+ elif "hostingenvuri" in url:
+ content = self.hosting_env
+ elif "sharedconfiguri" in url:
+ content = self.shared_config
+ elif "certificatesuri" in url:
+ content = self.certs
+ elif "extensionsconfiguri" in url:
+ content = self.ext_conf
+ elif "manifest.xml" in url:
+ content = self.manifest
+ elif "ExampleHandlerLinux" in url:
+ content = self.ext
+ resp = MagicMock()
+ resp.status = httpclient.OK
+ resp.read = Mock(return_value=content)
+ return resp
+ else:
+ raise Exception("Bad url {0}".format(url))
+ resp = MagicMock()
+ resp.status = httpclient.OK
+ resp.read = Mock(return_value=content.encode("utf-8"))
+ return resp
+
+ def mock_crypt_util(self, *args, **kw):
+ #Partially patch instance method of class CryptUtil
+ cryptutil = CryptUtil(*args, **kw)
+ cryptutil.gen_transport_cert = Mock(side_effect=self.mock_gen_trans_cert)
+ return cryptutil
+
+ def mock_gen_trans_cert(self, trans_prv_file, trans_cert_file):
+ with open(trans_prv_file, 'w+') as prv_file:
+ prv_file.write(self.trans_prv)
+
+ with open(trans_cert_file, 'w+') as cert_file:
+ cert_file.write(self.trans_cert)
+
diff --git a/tests/protocol/test_metadata.py b/tests/protocol/test_metadata.py
new file mode 100644
index 0000000..fca1a82
--- /dev/null
+++ b/tests/protocol/test_metadata.py
@@ -0,0 +1,48 @@
+# Copyright 2014 Microsoft Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Requires Python 2.4+ and Openssl 1.0+
+#
+# Implements parts of RFC 2131, 1541, 1497 and
+# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
+# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
+
+from tests.tools import *
+from tests.protocol.mockmetadata import *
+from azurelinuxagent.utils.restutil import httpclient
+from azurelinuxagent.protocol.metadata import MetadataProtocol
+
+@patch("time.sleep")
+@patch("azurelinuxagent.protocol.metadata.restutil")
+class TestWireProtocolGetters(AgentTestCase):
+ def _test_getters(self, test_data, mock_restutil ,_):
+ mock_restutil.http_get.side_effect = test_data.mock_http_get
+
+ protocol = MetadataProtocol()
+ protocol.detect()
+ protocol.get_vminfo()
+ protocol.get_certs()
+ ext_handlers, etag= protocol.get_ext_handlers()
+ for ext_handler in ext_handlers.extHandlers:
+ protocol.get_ext_handler_pkgs(ext_handler)
+
+ def test_getters(self, *args):
+ test_data = MetadataProtocolData(DATA_FILE)
+ self._test_getters(test_data, *args)
+
+ def test_getters_no(self, *args):
+ test_data = MetadataProtocolData(DATA_FILE_NO_EXT)
+ self._test_getters(test_data, *args)
+
+
diff --git a/tests/test_datacontract.py b/tests/protocol/test_restapi.py
index 4d4edd7..656ecc6 100644
--- a/tests/test_datacontract.py
+++ b/tests/protocol/test_restapi.py
@@ -18,14 +18,13 @@
# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-import tests.env
from tests.tools import *
import uuid
import unittest
import os
import shutil
import time
-from azurelinuxagent.protocol.common import *
+from azurelinuxagent.protocol.restapi import *
class SampleDataContract(DataContract):
def __init__(self):
diff --git a/tests/protocol/test_wire.py b/tests/protocol/test_wire.py
new file mode 100644
index 0000000..4c38c13
--- /dev/null
+++ b/tests/protocol/test_wire.py
@@ -0,0 +1,85 @@
+# Copyright 2014 Microsoft Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Requires Python 2.4+ and Openssl 1.0+
+#
+# Implements parts of RFC 2131, 1541, 1497 and
+# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
+# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
+
+from tests.tools import *
+from tests.protocol.mockwiredata import *
+import uuid
+import unittest
+import os
+import time
+from azurelinuxagent.utils.restutil import httpclient
+from azurelinuxagent.utils.cryptutil import CryptUtil
+from azurelinuxagent.protocol.restapi import *
+from azurelinuxagent.protocol.wire import WireClient, WireProtocol, \
+ TRANSPORT_PRV_FILE_NAME, \
+ TRANSPORT_CERT_FILE_NAME
+
+data_with_bom = b'\xef\xbb\xbfhehe'
+
+@patch("time.sleep")
+@patch("azurelinuxagent.protocol.wire.CryptUtil")
+@patch("azurelinuxagent.protocol.wire.restutil")
+class TestWireProtocolGetters(AgentTestCase):
+
+ def _test_getters(self, test_data, mock_restutil, MockCryptUtil, _):
+ mock_restutil.http_get.side_effect = test_data.mock_http_get
+ MockCryptUtil.side_effect = test_data.mock_crypt_util
+
+ protocol = WireProtocol("foo.bar")
+ protocol.detect()
+ protocol.get_vminfo()
+ protocol.get_certs()
+ ext_handlers, etag = protocol.get_ext_handlers()
+ for ext_handler in ext_handlers.extHandlers:
+ protocol.get_ext_handler_pkgs(ext_handler)
+
+ crt1 = os.path.join(self.tmp_dir,
+ '33B0ABCE4673538650971C10F7D7397E71561F35.crt')
+ crt2 = os.path.join(self.tmp_dir,
+ '4037FBF5F1F3014F99B5D6C7799E9B20E6871CB3.crt')
+ prv2 = os.path.join(self.tmp_dir,
+ '4037FBF5F1F3014F99B5D6C7799E9B20E6871CB3.prv')
+
+ self.assertTrue(os.path.isfile(crt1))
+ self.assertTrue(os.path.isfile(crt2))
+ self.assertTrue(os.path.isfile(prv2))
+
+ def test_getters(self, *args):
+ """Normal case"""
+ test_data = WireProtocolData(DATA_FILE)
+ self._test_getters(test_data, *args)
+
+ def test_getters_no_ext(self, *args):
+ """Provision with agent is not checked"""
+ test_data = WireProtocolData(DATA_FILE_NO_EXT)
+ self._test_getters(test_data, *args)
+
+ def test_getters_ext_no_settings(self, *args):
+ """Extensions without any settings"""
+ test_data = WireProtocolData(DATA_FILE_EXT_NO_SETTINGS)
+ self._test_getters(test_data, *args)
+
+ def test_getters_ext_no_public(self, *args):
+ """Extensions without any public settings"""
+ test_data = WireProtocolData(DATA_FILE_EXT_NO_PUBLIC)
+ self._test_getters(test_data, *args)
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tests/test.crt b/tests/test.crt
deleted file mode 100644
index e87c5f9..0000000
--- a/tests/test.crt
+++ /dev/null
@@ -1,17 +0,0 @@
-Bag Attributes: <Empty Attributes>
-subject=/C=ab/ST=ab/L=ab/O=ab/OU=ab/CN=ab/emailAddress=ab
-issuer=/C=ab/ST=ab/L=ab/O=ab/OU=ab/CN=ab/emailAddress=ab
------BEGIN CERTIFICATE-----
-MIICOTCCAaICCQD7F0nb+GtpcTANBgkqhkiG9w0BAQsFADBhMQswCQYDVQQGEwJh
-YjELMAkGA1UECAwCYWIxCzAJBgNVBAcMAmFiMQswCQYDVQQKDAJhYjELMAkGA1UE
-CwwCYWIxCzAJBgNVBAMMAmFiMREwDwYJKoZIhvcNAQkBFgJhYjAeFw0xNDA4MDUw
-ODIwNDZaFw0xNTA4MDUwODIwNDZaMGExCzAJBgNVBAYTAmFiMQswCQYDVQQIDAJh
-YjELMAkGA1UEBwwCYWIxCzAJBgNVBAoMAmFiMQswCQYDVQQLDAJhYjELMAkGA1UE
-AwwCYWIxETAPBgkqhkiG9w0BCQEWAmFiMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB
-iQKBgQC4Vugyj4uAKGYHW/D1eAg1DmLAv01e+9I0zIi8HzJxP87MXmS8EdG5SEzR
-N6tfQQie76JBSTYI4ngTaVCKx5dVT93LiWxLV193Q3vs/HtwwH1fLq0rAKUhREQ6
-+CsRGNyeVfJkNsxAvNvQkectnYuOtcDxX5n/25eWAofobxVbSQIDAQABMA0GCSqG
-SIb3DQEBCwUAA4GBAF20gkq/DeUSXkZA+jjmmbCPioB3KL63GpoTXfP65d6yU4xZ
-TlMoLkqGKe3WoXmhjaTOssulgDAGA24IeWy/u7luH+oHdZEmEufFhj4M7tQ1pAhN
-CT8JCL2dI3F76HD6ZutTOkwRar3PYk5q7RsSJdAemtnwVpgp+RBMtbmct7MQ
------END CERTIFICATE-----
diff --git a/tests/test.prv b/tests/test.prv
deleted file mode 100644
index 9d6ab87..0000000
--- a/tests/test.prv
+++ /dev/null
@@ -1,15 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-MIICXAIBAAKBgQC4Vugyj4uAKGYHW/D1eAg1DmLAv01e+9I0zIi8HzJxP87MXmS8
-EdG5SEzRN6tfQQie76JBSTYI4ngTaVCKx5dVT93LiWxLV193Q3vs/HtwwH1fLq0r
-AKUhREQ6+CsRGNyeVfJkNsxAvNvQkectnYuOtcDxX5n/25eWAofobxVbSQIDAQAB
-AoGAIakE506c238E+m0Id9o+LWn+EFIeT6zN+oQqp6dOr61GFr1ZyZm7YQjZtg5j
-RZZ7e4Iob6Fts3ufD3RYl67QbBzRwsKwI7sAmzdCmqkopY2H6xv421cEGjkqZIJV
-2Xyp9Idji6GfUB6+t1SZDOssbZx3SUkyim0hixK2HCJT4u0CQQDw6rNLZwEmwuhY
-z1jSERyeTtIcRJ47+Y79tX2xmkyKxZ2Kf28V3Fw/6biCIlmuvxHNhlLijimOME7/
-rkqDiscnAkEAw+FpkM96xLlDCqNL2AcNxVnmNyO0Boxw0AKrogfcnDh6S3rD5tZQ
-IdcIAsEYNjhEJ+/hVCByIUArC885PTzQDwJBAMaDfm3ZWHeKD05uvG+MLhq8NCGa
-4Q/mWU7xZ7sau4t1vpTK4MwQoesAOUrx5xg41QCXeGC6Z7+ESvQft8Kgbe0CQAkS
-OExPf3T6y2MDuvBvKzEXf7TP/3dKK7NGXGJtkMbfSrKSJd5b0GwwxBs0jAV+x5E9
-56Z4tjBaA2RRnWn7lfsCQA5SWuDMtlOzyWir09fparnnRL1JFvOwDAHTE0iwS8dO
-UFHIIw4nqqUYuHb+r/eyRzVtokJ9bSPZOjtTWSVL4W4=
------END RSA PRIVATE KEY-----
diff --git a/tests/test_certificates.py b/tests/test_certificates.py
deleted file mode 100644
index 18f28c4..0000000
--- a/tests/test_certificates.py
+++ /dev/null
@@ -1,199 +0,0 @@
-# Copyright 2014 Microsoft Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# Requires Python 2.4+ and Openssl 1.0+
-#
-# Implements parts of RFC 2131, 1541, 1497 and
-# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
-# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-
-import tests.env
-from .tools import *
-import uuid
-import unittest
-import os
-import json
-import azurelinuxagent.utils.fileutil as fileutil
-import azurelinuxagent.protocol.v1 as v1
-
-certs_sample=u"""\
-<?xml version="1.0" encoding="utf-8"?>
-<CertificateFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="certificates10.xsd">
- <Version>2012-11-30</Version>
- <Incarnation>12</Incarnation>
- <Format>Pkcs7BlobWithPfxContents</Format>
- <Data>MIINswYJKoZIhvcNAQcDoIINpDCCDaACAQIxggEwMIIBLAIBAoAUvyL+x6GkZXog
-QNfsXRZAdD9lc7IwDQYJKoZIhvcNAQEBBQAEggEArhMPepD/RqwdPcHEVqvrdZid
-72vXrOCuacRBhwlCGrNlg8oI+vbqmT6CSv6thDpet31ALUzsI4uQHq1EVfV1+pXy
-NlYD1CKhBCoJxs2fSPU4rc8fv0qs5JAjnbtW7lhnrqFrXYcyBYjpURKfa9qMYBmj
-NdijN+1T4E5qjxPr7zK5Dalp7Cgp9P2diH4Nax2nixotfek3MrEFBaiiegDd+7tE
-ux685GWYPqB5Fn4OsDkkYOdb0OE2qzLRrnlCIiBCt8VubWH3kMEmSCxBwSJupmQ8
-sxCWk+sBPQ9gJSt2sIqfx/61F8Lpu6WzP+ZOnMLTUn2wLU/d1FN85HXmnQALzTCC
-DGUGCSqGSIb3DQEHATAUBggqhkiG9w0DBwQIbEcBfddWPv+AggxAAOAt/kCXiffe
-GeJG0P2K9Q18XZS6Rz7Xcz+Kp2PVgqHKRpPjjmB2ufsRO0pM4z/qkHTOdpfacB4h
-gz912D9U04hC8mt0fqGNTvRNAFVFLsmo7KXc/a8vfZNrGWEnYn7y1WfP52pqA/Ei
-SNFf0NVtMyqg5Gx+hZ/NpWAE5vcmRRdoYyWeg13lhlW96QUxf/W7vY/D5KpAGACI
-ok79/XI4eJkbq3Dps0oO/difNcvdkE74EU/GPuL68yR0CdzzafbLxzV+B43TBRg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q
-4HuL22KSII6Fb0VvkWkBAg19uwDRpw78VC0YxBm0J02Yi8b1AaOhi3dTVzFFlWeh
-r6oK/PAAcMKxGkyCgMAZ3hstsltGkfXMoBwhW+yL6nyOYZ2p9vpzAGrjkwKBgQDF
-0huzbyXVt/AxpTEhv07U0enfjI6tnp4COp5q8zyskEph8yD5VjK/yZh5DpmFs6Kw
-dnYUFpbzbKM51tToMNr3nnYNjEnGYVfwWgvNHok1x9S0KLcjSu3ki7DmmGdbfcYq
-A2uEyd5CFyx5Nr+tQOwUyeiPbiFG6caHNmQExLoiAQKBgFPy9H8///xsadYmZ18k
-r77R2CvU7ArxlLfp9dr19aGYKvHvnpsY6EuChkWfy8Xjqn3ogzgrHz/rn3mlGUpK
-vbtwtsknAHtTbotXJwfaBZv2RGgGRr3DzNo6ll2Aez0lNblZFXq132h7+y5iLvar
-4euORaD/fuM4UPlR5mN+bypU
------END PRIVATE KEY-----
-"""
-
-def MockGetOpensslCmd():
- return 'openssl'
-
-class TestCertificates(unittest.TestCase):
-
- def test_certificates(self):
- crt1 = '/tmp/33B0ABCE4673538650971C10F7D7397E71561F35.crt'
- crt2 = '/tmp/4037FBF5F1F3014F99B5D6C7799E9B20E6871CB3.crt'
- prv2 = '/tmp/4037FBF5F1F3014F99B5D6C7799E9B20E6871CB3.prv'
- os.chdir('/tmp')
- if os.path.isfile(crt1):
- os.remove(crt1)
- if os.path.isfile(crt2):
- os.remove(crt2)
- if os.path.isfile(prv2):
- os.remove(prv2)
- fileutil.write_file(os.path.join('/tmp', "TransportCert.pem"),
- transport_cert)
- fileutil.write_file(os.path.join('/tmp', "TransportPrivate.pem"),
- transport_private)
- client = v1.WireClient("http://foo.bar")
- config = v1.Certificates(client, certs_sample)
- self.assertNotEquals(None, config)
- self.assertTrue(os.path.isfile(crt1))
- self.assertTrue(os.path.isfile(crt2))
- self.assertTrue(os.path.isfile(prv2))
-
- self.assertNotEquals(0, len(config.cert_list.certificates))
- cert = config.cert_list.certificates[0]
- self.assertNotEquals(None, cert.thumbprint)
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/test_conf.py b/tests/test_conf.py
deleted file mode 100644
index 204e4f5..0000000
--- a/tests/test_conf.py
+++ /dev/null
@@ -1,69 +0,0 @@
-# Copyright 2014 Microsoft Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# Requires Python 2.4+ and Openssl 1.0+
-#
-# Implements parts of RFC 2131, 1541, 1497 and
-# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
-# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-
-import os
-import tests.env
-import uuid
-import unittest
-import tests.tools as tools
-import azurelinuxagent.utils.fileutil as fileutil
-import azurelinuxagent.conf as conf
-from azurelinuxagent.exception import *
-
-TestConf="""\
-#
-# This is comment
-#
-foo.bar.switch=y
-foo.bar.switch2=n
-foo.bar.str=foobar
-foo.bar.int=300
-
-"""
-
-class TestConfiguration(unittest.TestCase):
- def test_parse_conf(self):
- config = conf.ConfigurationProvider()
- config.load(TestConf)
- self.assertEquals(True, config.get_switch("foo.bar.switch"))
- self.assertEquals(False, config.get_switch("foo.bar.switch2"))
- self.assertEquals(False, config.get_switch("foo.bar.switch3"))
- self.assertEquals(True, config.get_switch("foo.bar.switch4", True))
- self.assertEquals("foobar", config.get("foo.bar.str"))
- self.assertEquals("foobar1", config.get("foo.bar.str1", "foobar1"))
- self.assertEquals(300, config.get_int("foo.bar.int"))
- self.assertEquals(-1, config.get_int("foo.bar.int2"))
- self.assertEquals(-1, config.get_int("foo.bar.str"))
-
- def test_parse_malformed_conf(self):
- config = conf.ConfigurationProvider()
- self.assertRaises(AgentConfigError, config.load, None)
-
- def test_load_conf_file(self):
- with open('/tmp/test_conf', 'w') as F:
- F.write(TestConf)
- F.close()
-
- config = conf.ConfigurationProvider()
- conf.load_conf('/tmp/test_conf', conf=config)
- self.assertEquals(True, config.get_switch("foo.bar.switch"), False)
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/test_deprovision.py b/tests/test_deprovision.py
deleted file mode 100644
index 8bad6b9..0000000
--- a/tests/test_deprovision.py
+++ /dev/null
@@ -1,54 +0,0 @@
-# Copyright 2014 Microsoft Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# Requires Python 2.4+ and Openssl 1.0+
-#
-# Implements parts of RFC 2131, 1541, 1497 and
-# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
-# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-
-import tests.env
-from tests.tools import *
-import unittest
-import azurelinuxagent.distro.default.deprovision as deprovision_handler
-
-def MockAction(param):
- #print param
- pass
-
-def MockSetup(self, deluser):
- warnings = ["Print warning to console"]
- actions = [
- deprovision_handler.DeprovisionAction(MockAction, ['Take action'])
- ]
- return warnings, actions
-
-class TestDeprovisionHandler(unittest.TestCase):
- def test_setup(self):
- handler = deprovision_handler.DeprovisionHandler()
- warnings, actions = handler.setup(False)
- self.assertNotEquals(None, warnings)
- self.assertNotEquals(0, len(warnings))
- self.assertNotEquals(None, actions)
- self.assertNotEquals(0, len(actions))
- self.assertEquals(deprovision_handler.DeprovisionAction, type(actions[0]))
-
-
- @mock(deprovision_handler.DeprovisionHandler, 'setup', MockSetup)
- def test_deprovision(self):
- handler = deprovision_handler.DeprovisionHandler()
- handler.deprovision(force=True)
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/test_dhcp.py b/tests/test_dhcp.py
deleted file mode 100644
index 2206325..0000000
--- a/tests/test_dhcp.py
+++ /dev/null
@@ -1,68 +0,0 @@
-# Copyright 2014 Microsoft Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# Requires Python 2.4+ and Openssl 1.0+
-#
-# Implements parts of RFC 2131, 1541, 1497 and
-# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
-# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-
-import tests.env as env
-from tests.tools import *
-import uuid
-import unittest
-import os
-import json
-import azurelinuxagent.utils.fileutil as fileutil
-import azurelinuxagent.distro.default.dhcp as dhcp_handler
-
-SampleDhcpResponse = None
-with open(os.path.join(env.test_root, "dhcp"), 'rb') as F:
- SampleDhcpResponse = F.read()
-
-mock_socket_send = MockFunc('socket_send', SampleDhcpResponse)
-mock_gen_trans_id = MockFunc('gen_trans_id', "\xC6\xAA\xD1\x5D")
-mock_get_mac_addr = MockFunc('get_mac_addr', "\x00\x15\x5D\x38\xAA\x38")
-mock_send_dhcp_failed = MockFunc(retval=None)
-
-class TestdhcpHandler(unittest.TestCase):
-
- def test_build_dhcp_req(self):
- req = dhcp_handler.build_dhcp_request(mock_get_mac_addr())
- self.assertNotEquals(None, req)
-
- @mock(dhcp_handler, "gen_trans_id", mock_gen_trans_id)
- @mock(dhcp_handler, "socket_send", mock_socket_send)
- def test_send_dhcp_req(self):
- req = dhcp_handler.build_dhcp_request(mock_get_mac_addr())
- resp = dhcp_handler.send_dhcp_request(req)
- self.assertNotEquals(None, resp)
-
- @mock(dhcp_handler, "send_dhcp_request", mock_send_dhcp_failed)
- def test_send_dhcp_failed(self):
- dhcp = dhcp_handler.DhcpHandler()
- dhcp.probe()
-
- @mock(dhcp_handler, "socket_send", mock_socket_send)
- @mock(dhcp_handler, "gen_trans_id", mock_gen_trans_id)
- @mock(dhcp_handler.OSUTIL, "get_mac_addr", mock_get_mac_addr)
- @mock(dhcp_handler.fileutil, "write_file", MockFunc())
- def test_handle_dhcp(self):
- dh = dhcp_handler.DhcpHandler()
- dh.probe()
- self.assertEquals("10.62.144.1", dh.gateway)
- self.assertEquals("10.62.144.140", dh.endpoint)
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/test_distroLoader.py b/tests/test_distroLoader.py
deleted file mode 100644
index 16987c5..0000000
--- a/tests/test_distroLoader.py
+++ /dev/null
@@ -1,42 +0,0 @@
-# Copyright 2014 Microsoft Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# Requires Python 2.4+ and Openssl 1.0+
-#
-# Implements parts of RFC 2131, 1541, 1497 and
-# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
-# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-
-import tests.env
-from tests.tools import *
-import unittest
-from azurelinuxagent.utils.osutil import OSUTIL, OSUtilError
-from azurelinuxagent.handler import HANDLERS
-import azurelinuxagent.distro.default.osutil as osutil
-
-class TestDistroLoader(unittest.TestCase):
- def test_loader(self):
- self.assertNotEquals(osutil.DefaultOSUtil, type(OSUTIL))
- self.assertNotEquals(None, HANDLERS.init_handler)
- self.assertNotEquals(None, HANDLERS.main_handler)
- self.assertNotEquals(None, HANDLERS.scvmm_handler)
- self.assertNotEquals(None, HANDLERS.dhcp_handler)
- self.assertNotEquals(None, HANDLERS.env_handler)
- self.assertNotEquals(None, HANDLERS.provision_handler)
- self.assertNotEquals(None, HANDLERS.resource_disk_handler)
- self.assertNotEquals(None, HANDLERS.env_handler)
- self.assertNotEquals(None, HANDLERS.deprovision_handler)
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/test_envmon.py b/tests/test_envmon.py
deleted file mode 100644
index 74b61ee..0000000
--- a/tests/test_envmon.py
+++ /dev/null
@@ -1,52 +0,0 @@
-# Copyright 2014 Microsoft Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# Requires Python 2.4+ and Openssl 1.0+
-#
-# Implements parts of RFC 2131, 1541, 1497 and
-# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
-# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-
-import tests.env
-from tests.tools import *
-import unittest
-import time
-from azurelinuxagent.future import text
-from azurelinuxagent.utils.osutil import OSUTIL
-from azurelinuxagent.distro.default.env import EnvMonitor
-
-class MockDhcpHandler(object):
- def conf_routes(self):
- pass
-
-def mock_get_dhcp_pid():
- return "1234"
-
-def mock_dhcp_pid_change():
- return text(time.time())
-
-class TestEnvMonitor(unittest.TestCase):
-
- @mock(OSUTIL, 'get_dhcp_pid', mock_get_dhcp_pid)
- def test_dhcp_pid_not_change(self):
- monitor = EnvMonitor(MockDhcpHandler())
- monitor.handle_dhclient_restart()
-
- @mock(OSUTIL, 'get_dhcp_pid', mock_dhcp_pid_change)
- def test_dhcp_pid_change(self):
- monitor = EnvMonitor(MockDhcpHandler())
- monitor.handle_dhclient_restart()
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/test_event.py b/tests/test_event.py
deleted file mode 100644
index fcf67c9..0000000
--- a/tests/test_event.py
+++ /dev/null
@@ -1,53 +0,0 @@
-# Copyright 2014 Microsoft Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# Requires Python 2.4+ and Openssl 1.0+
-#
-# Implements parts of RFC 2131, 1541, 1497 and
-# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
-# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-
-import tests.env
-from .tools import *
-import uuid
-import unittest
-import os
-import shutil
-import azurelinuxagent.utils.fileutil as fileutil
-import azurelinuxagent.event as evt
-import azurelinuxagent.protocol as prot
-
-class MockProtocol(object):
- def get_vminfo(self):
- return prot.VMInfo(subscriptionId='foo', vmName='bar')
- def report_event(self, data): pass
-
-class TestEvent(unittest.TestCase):
- def test_save(self):
- if not os.path.exists("/tmp/events"):
- os.mkdir("/tmp/events")
- evt.add_event("Test", "Test", True)
- eventsFile = os.listdir("/tmp/events")
- self.assertNotEquals(0, len(eventsFile))
- shutil.rmtree("/tmp/events")
-
- @mock(evt.prot.FACTORY, 'get_default_protocol',
- MockFunc(retval=MockProtocol()))
- def test_init_sys_info(self):
- monitor = evt.EventMonitor()
- monitor.init_sysinfo()
- self.assertNotEquals(0, len(monitor.sysinfo))
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/test_ext.py b/tests/test_ext.py
deleted file mode 100644
index a68a851..0000000
--- a/tests/test_ext.py
+++ /dev/null
@@ -1,223 +0,0 @@
-# Copyright 2014 Microsoft Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# Requires Python 2.4+ and Openssl 1.0+
-#
-# Implements parts of RFC 2131, 1541, 1497 and
-# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
-# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-
-import tests.env
-from tests.tools import *
-import uuid
-import unittest
-import os
-import json
-import azurelinuxagent.logger as logger
-from azurelinuxagent.utils.osutil import OSUTIL
-import azurelinuxagent.utils.fileutil as fileutil
-import azurelinuxagent.protocol as prot
-import azurelinuxagent.distro.default.extension as ext
-
-ext_sample_json = {
- "name":"TestExt",
- "properties":{
- "version":"2.0",
- "state":"enabled",
- "upgradePolicy":"auto",
- "extensions":[{
- "sequenceNumber": 0,
- "publicSettings": "",
- "protectedSettings": "",
- "certificateThumbprint": ""
- }],
- "versionUris":[{
- "version":"2.1",
- "uris":["http://foo.bar"]
- },{
- "version":"2.0",
- "uris":["http://foo.bar"]
- }]
- }
-}
-ext_sample = prot.ExtHandler()
-prot.set_properties("extensions", ext_sample, ext_sample_json)
-
-pkd_list_sample_str={
- "versions": [{
- "version": "2.0",
- "uris":[{
- "uri":"http://foo.bar"
- }]
- },{
- "version": "2.1",
- "uris":[{
- "uri":"http://foo.bar"
- }]
- }]
-}
-pkg_list_sample = prot.ExtHandlerPackageList()
-prot.set_properties("packages", pkg_list_sample, pkd_list_sample_str)
-
-manifest_sample_str = {
- "handlerManifest":{
- "installCommand": "echo 'install'",
- "uninstallCommand": "echo 'uninstall'",
- "updateCommand": "echo 'update'",
- "enableCommand": "echo 'enable'",
- "disableCommand": "echo 'disable'",
- }
-}
-manifest_sample = ext.HandlerManifest(manifest_sample_str)
-
-ext_status_sample="""
-[{
- "version": 1.0,
- "timestampUTC": "2015-11-12T06:59:48Z",
- "status": {
- "name": "<Handler workload name>",
- "operation": "<name of the operation being performed>",
- "configurationAppliedTime": "2015-11-12T06:59:48Z",
- "status": "error",
- "code": 0,
- "formattedMessage": {
- "lang": "en-US",
- "message": "formatted user message"
- },
- "substatus": [{
- "name": "<Handler workload subcomponent name>",
- "status": "error",
- "code": 0 ,
- "formattedMessage": {
- "lang": "lang[-locale]",
- "message": "formatted user message"
- }
- },{
- "status": "error"
- }]
- }
-}]
-"""
-
-ext_status_sample_min="""
-[{
- "version": 1.0,
- "timestampUTC": "2015-11-12T06:59:48Z",
- "status": {
- "status": "error"
- }
-}]
-"""
-
-def mock_load_manifest(self):
- return manifest_sample
-
-mock_launch_command = MockFunc()
-mock_set_state = MockFunc()
-
-def mock_download(self):
- fileutil.mkdir(self.get_base_dir())
- fileutil.write_file(self.get_manifest_file(), json.dumps(manifest_sample_str))
-
-#logger.LoggerInit("/dev/null", "/dev/stdout")
-class TestExtensions(unittest.TestCase):
-
- def test_load_ext(self):
- libDir = OSUTIL.get_lib_dir()
- test_ext1 = os.path.join(libDir, 'TestExt-1.0')
- test_ext2 = os.path.join(libDir, 'TestExt-2.0')
- test_ext2 = os.path.join(libDir, 'TestExt-2.1')
- for path in [test_ext1, test_ext2]:
- if not os.path.isdir(path):
- os.mkdir(path)
- test_ext = ext.get_installed_version('TestExt')
- self.assertEqual('2.1', test_ext)
-
- def test_getters(self):
- test_ext = ext.ExtHandlerInstance(ext_sample, pkg_list_sample,
- ext_sample.properties.version, False)
- self.assertEqual("/tmp/TestExt-2.0", test_ext.get_base_dir())
- self.assertEqual("/tmp/TestExt-2.0/status", test_ext.get_status_dir())
- self.assertEqual("/tmp/TestExt-2.0/status/0.status",
- test_ext.get_status_file())
- self.assertEqual("/tmp/handler_state/TestExt-2.0/0.state",
- test_ext.get_handler_state_file())
- self.assertEqual("/tmp/handler_state/TestExt-2.0/0.error",
- test_ext.get_handler_state_err_file())
- self.assertEqual("/tmp/TestExt-2.0/config", test_ext.get_conf_dir())
- self.assertEqual("/tmp/TestExt-2.0/config/0.settings",
- test_ext.get_settings_file())
- self.assertEqual("/tmp/TestExt-2.0/heartbeat.log",
- test_ext.get_heartbeat_file())
- self.assertEqual("/tmp/TestExt-2.0/HandlerManifest.json",
- test_ext.get_manifest_file())
- self.assertEqual("/tmp/TestExt-2.0/HandlerEnvironment.json",
- test_ext.get_env_file())
- self.assertEqual("/tmp/log/TestExt/2.0", test_ext.get_log_dir())
-
- test_ext = ext.ExtHandlerInstance(ext_sample, pkg_list_sample,
- "2.1", False)
- self.assertEqual("/tmp/TestExt-2.1", test_ext.get_base_dir())
- self.assertEqual("2.1", test_ext.get_target_version())
-
- @mock(ext.ExtHandlerInstance, 'load_manifest', mock_load_manifest)
- @mock(ext.ExtHandlerInstance, 'launch_command', mock_launch_command)
- @mock(ext.ExtHandlerInstance, 'set_state', mock_set_state)
- def test_handle_uninstall(self):
- mock_launch_command.args = None
- mock_set_state.args = None
- test_ext = ext.ExtHandlerInstance(ext_sample, pkg_list_sample,
- ext_sample.properties.version, False)
- if not os.path.isdir(test_ext.get_base_dir()):
- os.makedirs(test_ext.get_base_dir())
- test_ext.handle_uninstall()
- self.assertEqual(None, mock_launch_command.args)
- self.assertEqual(None, mock_set_state.args)
-
- test_ext = ext.ExtHandlerInstance(ext_sample, pkg_list_sample,
- ext_sample.properties.version, True)
- if not os.path.isdir(test_ext.get_base_dir()):
- os.makedirs(test_ext.get_base_dir())
- test_ext.handle_uninstall()
- self.assertEqual(manifest_sample.get_uninstall_command(),
- mock_launch_command.args[0])
-
- @mock(ext.ExtHandlerInstance, 'upgrade', MockFunc())
- @mock(ext.ExtHandlerInstance, 'enable', MockFunc())
- @mock(ext.ExtHandlerInstance, 'download', MockFunc())
- @mock(ext.ExtHandlerInstance, 'init_dir', MockFunc())
- @mock(ext.ExtHandlerInstance, 'install', MockFunc())
- def test_handle_enable(self):
- #Test enable
- test_ext = ext.ExtHandlerInstance(ext_sample, pkg_list_sample,
- ext_sample.properties.version, False)
- test_ext.handle_enable()
-
- #Test upgrade
- test_ext = ext.ExtHandlerInstance(ext_sample, pkg_list_sample,
- "2.0" , True)
- test_ext.handle_enable()
-
- def test_status_convert(self):
- data = json.loads(ext_status_sample)
- ext_status = prot.ExtensionStatus()
- ext.parse_ext_status(ext_status, data)
-
- data = json.loads(ext_status_sample_min)
- ext_status = prot.ExtensionStatus()
- ext.parse_ext_status(ext_status, data)
-
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/test_extensionsconfig.py b/tests/test_extensionsconfig.py
deleted file mode 100644
index 505c73d..0000000
--- a/tests/test_extensionsconfig.py
+++ /dev/null
@@ -1,159 +0,0 @@
-# Copyright 2014 Microsoft Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# Requires Python 2.4+ and Openssl 1.0+
-#
-# Implements parts of RFC 2131, 1541, 1497 and
-# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
-# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-
-import tests.env
-import tests.tools as tools
-import uuid
-import unittest
-import os
-import json
-import azurelinuxagent.protocol.v1 as v1
-
-ext_conf_sample=u"""\
-<Extensions version="1.0.0.0" goalStateIncarnation="9"><GuestAgentExtension xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
- <GAFamilies>
- <GAFamily>
- <Name>Win8</Name>
- <Uris>
- <Uri>http://rdfepirv2hknprdstr03.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
- <Uri>http://rdfepirv2hknprdstr04.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
- <Uri>http://rdfepirv2hknprdstr05.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
- <Uri>http://rdfepirv2hknprdstr06.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
- <Uri>http://rdfepirv2hknprdstr07.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
- <Uri>http://rdfepirv2hknprdstr08.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
- <Uri>http://rdfepirv2hknprdstr09.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
- <Uri>http://rdfepirv2hknprdstr10.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
- <Uri>http://rdfepirv2hknprdstr11.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
- <Uri>http://rdfepirv2hknprdstr12.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
- <Uri>http://zrdfepirv2hk2prdstr01.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win8_asiaeast_manifest.xml</Uri>
- </Uris>
- </GAFamily>
- <GAFamily>
- <Name>Win7</Name>
- <Uris>
- <Uri>http://rdfepirv2hknprdstr03.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
- <Uri>http://rdfepirv2hknprdstr04.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
- <Uri>http://rdfepirv2hknprdstr05.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
- <Uri>http://rdfepirv2hknprdstr06.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
- <Uri>http://rdfepirv2hknprdstr07.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
- <Uri>http://rdfepirv2hknprdstr08.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
- <Uri>http://rdfepirv2hknprdstr09.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
- <Uri>http://rdfepirv2hknprdstr10.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
- <Uri>http://rdfepirv2hknprdstr11.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
- <Uri>http://rdfepirv2hknprdstr12.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
- <Uri>http://zrdfepirv2hk2prdstr01.blob.core.windows.net/bfd5c281a7dc4e4b84381eb0b47e3aaf/Microsoft.WindowsAzure.GuestAgent_Win7_asiaeast_manifest.xml</Uri>
- </Uris>
- </GAFamily>
- </GAFamilies>
-</GuestAgentExtension>
-<Plugins>
- <Plugin name="OSTCExtensions.ExampleHandlerLinux" version="1.4" location="http://rdfepirv2hknprdstr03.blob.core.windows.net/b01058962be54ceca550a390fa5ff064/Microsoft.OSTCExtensions_CustomScriptForLinuxTest_asiaeast_manifest.xml" config="" state="enabled" autoUpgrade="true" failoverlocation="http://rdfepirv2hknprdstr04.blob.core.windows.net/b01058962be54ceca550a390fa5ff064/Microsoft.OSTCExtensions_CustomScriptForLinuxTest_asiaeast_manifest.xml" runAsStartupTask="false" isJson="true" />
-</Plugins>
-<PluginSettings>
- <Plugin name="OSTCExtensions.ExampleHandlerLinux" version="1.4">
- <RuntimeSettings seqNo="6">{"runtimeSettings":[{"handlerSettings":{"protectedSettingsCertThumbprint":"4037FBF5F1F3014F99B5D6C7799E9B20E6871CB3","protectedSettings":"MIICWgYJK","publicSettings":{"foo":"bar"}}}]}</RuntimeSettings>
- </Plugin>
-</PluginSettings>
-<StatusUploadBlob>https://yuezhatest.blob.core.windows.net/vhds/test-cs12.test-cs12.test-cs12.status?sr=b&amp;sp=rw&amp;se=9999-01-01&amp;sk=key1&amp;sv=2014-02-14&amp;sig=hfRh7gzUE7sUtYwke78IOlZOrTRCYvkec4hGZ9zZzXo%3D</StatusUploadBlob></Extensions>
-"""
-
-manifest_sample=u"""\
-<?xml version="1.0" encoding="utf-8"?>
-<PluginVersionManifest xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
- <Plugins>
- <Plugin>
- <Version>1.0</Version>
- <Uris>
- <Uri>http://blahblah</Uri>
- </Uris>
- </Plugin>
- <Plugin>
- <Version>1.1</Version>
- <Uris>
- <Uri>http://blahblah</Uri>
- </Uris>
- </Plugin>
- </Plugins>
- <InternalPlugins>
- <Plugin>
- <Version>1.2</Version>
- <Uris>
- <Uri>http://blahblah</Uri>
- </Uris>
- </Plugin>
-</InternalPlugins>
-</PluginVersionManifest>
-"""
-
-EmptySettings=u"""\
-<Extensions>
- <Plugins>
- <Plugin name="OSTCExtensions.ExampleHandlerLinux" version="1.4" location="http://rdfepirv2hknprdstr03.blob.core.windows.net/b01058962be54ceca550a390fa5ff064/Microsoft.OSTCExtensions_CustomScriptForLinuxTest_asiaeast_manifest.xml" config="" state="enabled" autoUpgrade="true" failoverlocation="http://rdfepirv2hknprdstr04.blob.core.windows.net/b01058962be54ceca550a390fa5ff064/Microsoft.OSTCExtensions_CustomScriptForLinuxTest_asiaeast_manifest.xml" runAsStartupTask="false" isJson="true" />
- </Plugins>
- <StatusUploadBlob>https://yuezhatest.blob.core.windows.net/vhds/test-cs12.test-cs12.test-cs12.status?sr=b&amp;sp=rw&amp;se=9999-01-01&amp;sk=key1&amp;sv=2014-02-14&amp;sig=hfRh7gzUE7sUtYwke78IOlZOrTRCYvkec4hGZ9zZzXo%3D</StatusUploadBlob>
-</Extensions>
-"""
-
-EmptyPublicSettings=u"""\
-<Extensions>
- <Plugins>
- <Plugin name="OSTCExtensions.ExampleHandlerLinux" version="1.4" location="http://rdfepirv2hknprdstr03.blob.core.windows.net/b01058962be54ceca550a390fa5ff064/Microsoft.OSTCExtensions_CustomScriptForLinuxTest_asiaeast_manifest.xml" config="" state="enabled" autoUpgrade="true" failoverlocation="http://rdfepirv2hknprdstr04.blob.core.windows.net/b01058962be54ceca550a390fa5ff064/Microsoft.OSTCExtensions_CustomScriptForLinuxTest_asiaeast_manifest.xml" runAsStartupTask="false" isJson="true" />
- </Plugins>
- <PluginSettings>
- <Plugin name="OSTCExtensions.ExampleHandlerLinux" version="1.4">
- <RuntimeSettings seqNo="6">{"runtimeSettings":[{"handlerSettings":{"protectedSettingsCertThumbprint":"4037FBF5F1F3014F99B5D6C7799E9B20E6871CB3","protectedSettings":"MIICWgYJK"}}]}</RuntimeSettings>
- </Plugin>
- </PluginSettings>
- <StatusUploadBlob>https://yuezhatest.blob.core.windows.net/vhds/test-cs12.test-cs12.test-cs12.status?sr=b&amp;sp=rw&amp;se=9999-01-01&amp;sk=key1&amp;sv=2014-02-14&amp;sig=hfRh7gzUE7sUtYwke78IOlZOrTRCYvkec4hGZ9zZzXo%3D</StatusUploadBlob>
-</Extensions>
-"""
-
-class TestExtensionsConfig(unittest.TestCase):
- def test_extensions_config(self):
- config = v1.ExtensionsConfig(ext_conf_sample)
- extensions = config.ext_handlers.extHandlers
- self.assertNotEquals(None, extensions)
- self.assertEquals(1, len(extensions))
- self.assertNotEquals(None, extensions[0])
- extension = extensions[0]
- self.assertEquals("OSTCExtensions.ExampleHandlerLinux",
- extension.name)
- self.assertEquals("1.4", extension.properties.version)
- self.assertEquals('auto', extension.properties.upgradePolicy)
- self.assertEquals("enabled", extension.properties.state)
- settings = extension.properties.extensions[0]
- self.assertEquals("4037FBF5F1F3014F99B5D6C7799E9B20E6871CB3",
- settings.certificateThumbprint)
- self.assertEquals("MIICWgYJK", settings.privateSettings)
- self.assertEquals(json.loads('{"foo":"bar"}'),
- settings.publicSettings)
-
- man = v1.ExtensionManifest(manifest_sample)
- self.assertNotEquals(None, man.pkg_list)
- self.assertEquals(3, len(man.pkg_list.versions))
-
- def test_empty_settings(self):
- config = v1.ExtensionsConfig(EmptySettings)
-
- def test_empty_public_settings(self):
- config = v1.ExtensionsConfig(EmptyPublicSettings)
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/test_goalstate.py b/tests/test_goalstate.py
deleted file mode 100644
index a18ce8d..0000000
--- a/tests/test_goalstate.py
+++ /dev/null
@@ -1,71 +0,0 @@
-# Copyright 2014 Microsoft Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# Requires Python 2.4+ and Openssl 1.0+
-#
-# Implements parts of RFC 2131, 1541, 1497 and
-# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
-# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-
-import tests.env
-import tests.tools as tools
-import uuid
-import unittest
-import os
-import test
-import azurelinuxagent.protocol.v1 as v1
-
-goal_state_sample=u"""\
-<?xml version="1.0" encoding="utf-8"?>
-<GoalState xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="goalstate10.xsd">
- <Version>2010-12-15</Version>
- <Incarnation>1</Incarnation>
- <Machine>
- <ExpectedState>Started</ExpectedState>
- <LBProbePorts>
- <Port>16001</Port>
- </LBProbePorts>
- </Machine>
- <Container>
- <ContainerId>c6d5526c-5ac2-4200-b6e2-56f2b70c5ab2</ContainerId>
- <RoleInstanceList>
- <RoleInstance>
- <InstanceId>MachineRole_IN_0</InstanceId>
- <State>Started</State>
- <Configuration>
- <HostingEnvironmentConfig>http://hostingenvuri/</HostingEnvironmentConfig>
- <SharedConfig>http://sharedconfiguri/</SharedConfig>
- <ExtensionsConfig>http://extensionsconfiguri/</ExtensionsConfig>
- <FullConfig>http://fullconfiguri/</FullConfig>
- </Configuration>
- </RoleInstance>
- </RoleInstanceList>
- </Container>
- </GoalState>
-"""
-
-class TestGoalState(unittest.TestCase):
- def test_goal_state(self):
- goal_state = v1.GoalState(goal_state_sample)
- self.assertEquals('1', goal_state.incarnation)
- self.assertNotEquals(None, goal_state.expected_state)
- self.assertNotEquals(None, goal_state.hosting_env_uri)
- self.assertNotEquals(None, goal_state.shared_conf_uri)
- self.assertEquals(None, goal_state.certs_uri)
- self.assertNotEquals(None, goal_state.ext_uri)
- self.assertNotEquals(None, goal_state.role_instance_id)
- self.assertNotEquals(None, goal_state.container_id)
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/test_import_waagent.py b/tests/test_import_waagent.py
deleted file mode 100644
index ec3f923..0000000
--- a/tests/test_import_waagent.py
+++ /dev/null
@@ -1,40 +0,0 @@
-# Copyright 2014 Microsoft Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# Requires Python 2.4+ and Openssl 1.0+
-#
-# Implements parts of RFC 2131, 1541, 1497 and
-# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
-# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-
-import tests.env
-import tests.tools as tools
-import os
-import imp
-import sys
-import uuid
-import unittest
-
-class TestImportWAAgent(unittest.TestCase):
- def test_import_waagent(self):
- agent_path = os.path.join(tools.parent, 'bin/waagent')
- if sys.version_info[0] == 2:
- waagent = imp.load_source('waagent', agent_path)
- self.assertNotEquals(None, waagent.LoggerInit)
- else:
- self.assertRaises(ImportError, imp.load_source, 'waagent',
- agent_path)
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/test_logger.py b/tests/test_logger.py
deleted file mode 100644
index 20e9259..0000000
--- a/tests/test_logger.py
+++ /dev/null
@@ -1,100 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright 2014 Microsoft Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# Requires Python 2.4+ and Openssl 1.0+
-#
-# Implements parts of RFC 2131, 1541, 1497 and
-# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
-# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-
-import tests.env
-import tests.tools as tools
-import uuid
-import unittest
-import azurelinuxagent.logger as logger
-from azurelinuxagent.future import text
-
-class TestLogger(unittest.TestCase):
-
- def test_no_appender(self):
- #The logger won't throw exception even if no appender.
- _logger = logger.Logger()
- _logger.verb("Assert no exception")
- _logger.info("Assert no exception")
- _logger.warn("Assert no exception")
- _logger.error("Assert no exception")
-
- def test_logger_format(self):
- _logger = logger.Logger()
- _logger.info("This is an exception {0}", Exception("Test"))
- _logger.info("This is an number {0}", 0)
- _logger.info("This is an boolean {0}", True)
- _logger.verb("{0}")
- _logger.verb("{0} {1}", 0, 1)
- _logger.info("{0} {1}", 0, 1)
- _logger.warn("{0} {1}", 0, 1)
- _logger.error("{0} {1}", 0, 1)
- _logger.add_appender(logger.AppenderType.STDOUT,
- logger.LogLevel.INFO, None)
- _logger.info(u"啊哈this is a utf-8 {0}", u'呵呵')
-
- def test_file_appender(self):
- _logger = logger.Logger()
- _logger.add_appender(logger.AppenderType.FILE,
- logger.LogLevel.INFO,
- '/tmp/testlog')
-
- msg = text(uuid.uuid4())
- _logger.info("Test logger: {0}", msg)
- self.assertTrue(tools.simple_file_grep('/tmp/testlog', msg))
-
- msg = text(uuid.uuid4())
- _logger.verb("Verbose should not be logged: {0}", msg)
- self.assertFalse(tools.simple_file_grep('/tmp/testlog', msg))
-
-
- def test_concole_appender(self):
- _logger = logger.Logger()
- _logger.add_appender(logger.AppenderType.CONSOLE,
- logger.LogLevel.VERBOSE,
- '/tmp/testlog')
-
- msg = text(uuid.uuid4())
- _logger.info("Test logger: {0}", msg)
- self.assertTrue(tools.simple_file_grep('/tmp/testlog', msg))
-
- msg = text(uuid.uuid4())
- _logger.verb("Test logger: {0}", msg)
- self.assertFalse(tools.simple_file_grep('/tmp/testlog', msg))
-
-
- def test_log_to_non_exists_dev(self):
- _logger = logger.Logger()
- _logger.add_appender(logger.AppenderType.CONSOLE,
- logger.LogLevel.INFO,
- '/dev/nonexists')
- _logger.info("something")
-
- def test_log_to_non_exists_file(self):
- _logger = logger.Logger()
- _logger.add_appender(logger.AppenderType.FILE,
- logger.LogLevel.INFO,
- '/tmp/nonexists')
- _logger.info("something")
-
-
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/test_metadata.py b/tests/test_metadata.py
deleted file mode 100644
index 8c34acc..0000000
--- a/tests/test_metadata.py
+++ /dev/null
@@ -1,36 +0,0 @@
-# Copyright 2014 Microsoft Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# Requires Python 2.4+ and Openssl 1.0+
-#
-# Implements parts of RFC 2131, 1541, 1497 and
-# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
-# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-
-import tests.env
-from tests.tools import *
-import unittest
-from azurelinuxagent.metadata import AGENT_NAME, AGENT_VERSION, \
- DISTRO_NAME, DISTRO_VERSION, DISTRO_CODE_NAME, \
- DISTRO_FULL_NAME
-
-class TestOSInfo(unittest.TestCase):
- def test_curr_os_info(self):
- self.assertNotEquals(None, DISTRO_NAME)
- self.assertNotEquals(None, DISTRO_VERSION)
- self.assertNotEquals(None, DISTRO_CODE_NAME)
- self.assertNotEquals(None, DISTRO_FULL_NAME)
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/test_osutil.py b/tests/test_osutil.py
deleted file mode 100644
index 95b8e17..0000000
--- a/tests/test_osutil.py
+++ /dev/null
@@ -1,174 +0,0 @@
-# Copyright 2014 Microsoft Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# Requires Python 2.4+ and Openssl 1.0+
-#
-# Implements parts of RFC 2131, 1541, 1497 and
-# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
-# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-
-import tests.env as env
-from tests.tools import *
-import uuid
-import unittest
-import os
-import shutil
-import time
-import azurelinuxagent.utils.fileutil as fileutil
-import azurelinuxagent.utils.shellutil as shellutil
-import azurelinuxagent.conf as conf
-from azurelinuxagent.utils.osutil import OSUTIL, OSUtilError
-import test
-
-class TestOSUtil(unittest.TestCase):
- def test_current_distro(self):
- self.assertNotEquals(None, OSUTIL)
-
-mount_list_sample="""\
-/dev/sda1 on / type ext4 (rw)
-proc on /proc type proc (rw)
-sysfs on /sys type sysfs (rw)
-devpts on /dev/pts type devpts (rw,gid=5,mode=620)
-tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
-none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
-/dev/sdb1 on /mnt/resource type ext4 (rw)
-"""
-
-class TestCurrOS(unittest.TestCase):
-#class TestCurrOS(object):
- def test_get_paths(self):
- self.assertNotEquals(None, OSUTIL.get_home())
- self.assertNotEquals(None, OSUTIL.get_lib_dir())
- self.assertNotEquals(None, OSUTIL.get_agent_pid_file_path())
- self.assertNotEquals(None, OSUTIL.get_conf_file_path())
- self.assertNotEquals(None, OSUTIL.get_dvd_mount_point())
- self.assertNotEquals(None, OSUTIL.get_ovf_env_file_path_on_dvd())
-
- @mock(fileutil, 'write_file', MockFunc())
- @mock(fileutil, 'append_file', MockFunc())
- @mock(fileutil, 'chmod', MockFunc())
- @mock(fileutil, 'read_file', MockFunc(retval=''))
- @mock(shellutil, 'run', MockFunc())
- @mock(shellutil, 'run_get_output', MockFunc(retval=[0, '']))
- def test_update_user_account(self):
- OSUTIL.useradd('foo')
- OSUTIL.chpasswd('foo', 'bar')
- OSUTIL.del_account('foo')
-
- @mock(fileutil, 'read_file', MockFunc(retval='root::::'))
- @mock(fileutil, 'write_file', MockFunc())
- def test_delete_root_password(self):
- OSUTIL.del_root_password()
- self.assertEquals('root:*LOCK*:14600::::::',
- fileutil.write_file.args[1])
-
- def test_cert_operation(self):
- if os.path.isfile('/tmp/test.prv'):
- os.remove('/tmp/test.prv')
- shutil.copyfile(os.path.join(env.test_root, 'test.prv'),
- '/tmp/test.prv')
- if os.path.isfile('/tmp/test.crt'):
- os.remove('/tmp/test.crt')
- shutil.copyfile(os.path.join(env.test_root, 'test.crt'),
- '/tmp/test.crt')
- pub1 = OSUTIL.get_pubkey_from_prv('/tmp/test.prv')
- pub2 = OSUTIL.get_pubkey_from_crt('/tmp/test.crt')
- self.assertEquals(pub1, pub2)
- thumbprint = OSUTIL.get_thumbprint_from_crt('/tmp/test.crt')
- self.assertEquals('33B0ABCE4673538650971C10F7D7397E71561F35', thumbprint)
-
- def test_selinux(self):
- if not OSUTIL.is_selinux_system():
- return
- isrunning = OSUTIL.is_selinux_enforcing()
- if not OSUTIL.is_selinux_enforcing():
- OSUTIL.set_selinux_enforce(0)
- self.assertEquals(False, OSUTIL.is_selinux_enforcing())
- OSUTIL.set_selinux_enforce(1)
- self.assertEquals(True, OSUTIL.is_selinux_enforcing())
- if os.path.isfile('/tmp/abc'):
- os.remove('/tmp/abc')
- fileutil.write_file('/tmp/abc', '')
- OSUTIL.set_selinux_context('/tmp/abc','unconfined_u:object_r:ssh_home_t:s')
- OSUTIL.set_selinux_enforce(1 if isrunning else 0)
-
- @mock(shellutil, 'run_get_output', MockFunc(retval=[0, '']))
- @mock(fileutil, 'write_file', MockFunc())
- def test_network_operation(self):
- OSUTIL.start_network()
- OSUTIL.allow_dhcp_broadcast()
- OSUTIL.gen_transport_cert()
- mac = OSUTIL.get_mac_addr()
- self.assertNotEquals(None, mac)
- OSUTIL.is_missing_default_route()
- OSUTIL.set_route_for_dhcp_broadcast('api')
- OSUTIL.remove_route_for_dhcp_broadcast('api')
- OSUTIL.route_add('', '', '')
- OSUTIL.get_dhcp_pid()
- OSUTIL.set_hostname('api')
- OSUTIL.publish_hostname('api')
-
- @mock(OSUTIL, 'get_home', MockFunc(retval='/tmp/home'))
- @mock(OSUTIL, 'get_pubkey_from_prv', MockFunc(retval=''))
- @mock(fileutil, 'chowner', MockFunc())
- def test_deploy_key(self):
- if os.path.isdir('/tmp/home'):
- shutil.rmtree('/tmp/home')
- fileutil.write_file('/tmp/foo.prv', '')
- OSUTIL.deploy_ssh_keypair("foo", ('$HOME/.ssh/id_rsa', 'foo'))
- OSUTIL.deploy_ssh_pubkey("foo", ('$HOME/.ssh/authorized_keys', None,
- 'ssh-rsa asdf'))
- OSUTIL.deploy_ssh_pubkey("foo", ('$HOME/.ssh/authorized_keys', 'foo',
- 'ssh-rsa asdf'))
- self.assertRaises(OSUtilError, OSUTIL.deploy_ssh_pubkey, "foo",
- ('$HOME/.ssh/authorized_keys', 'foo','hehe-rsa asdf'))
- self.assertTrue(os.path.isfile('/tmp/home/.ssh/id_rsa'))
- self.assertTrue(os.path.isfile('/tmp/home/.ssh/id_rsa.pub'))
- self.assertTrue(os.path.isfile('/tmp/home/.ssh/authorized_keys'))
-
- @mock(shellutil, 'run_get_output', MockFunc(retval=[0, '']))
- @mock(OSUTIL, 'get_sshd_conf_file_path', MockFunc(retval='/tmp/sshd_config'))
- def test_ssh_operation(self):
- shellutil.run_get_output.retval=[0,
- '2048 f1:fe:14:66:9d:46:9a:60:8b:8c:'
- '80:43:39:1c:20:9e root@api (RSA)']
- sshd_conf = OSUTIL.get_sshd_conf_file_path()
- self.assertEquals('/tmp/sshd_config', sshd_conf)
- if os.path.isfile(sshd_conf):
- os.remove(sshd_conf)
- shutil.copyfile(os.path.join(env.test_root, 'sshd_config'), sshd_conf)
- OSUTIL.set_ssh_client_alive_interval()
- OSUTIL.conf_sshd(True)
- self.assertTrue(simple_file_grep(sshd_conf,
- 'PasswordAuthentication no'))
- self.assertTrue(simple_file_grep(sshd_conf,
- 'ChallengeResponseAuthentication no'))
- self.assertTrue(simple_file_grep(sshd_conf,
- 'ClientAliveInterval 180'))
-
- @mock(shellutil, 'run_get_output', MockFunc(retval=[0, '']))
- @mock(OSUTIL, 'get_dvd_device', MockFunc(retval=[0, 'abc']))
- @mock(OSUTIL, 'get_mount_point', MockFunc(retval='/tmp/cdrom'))
- def test_mount(self):
- OSUTIL.mount_dvd()
- OSUTIL.umount_dvd()
- mount_point = OSUTIL.get_mount_point(mount_list_sample, '/dev/sda')
- self.assertNotEquals(None, mount_point)
-
- def test_getdvd(self):
- fileutil.write_file("/tmp/sr0", '')
- OSUTIL.get_dvd_device(dev_dir='/tmp')
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/test_ovfxml.py b/tests/test_ovfxml.py
deleted file mode 100644
index 7b6990b..0000000
--- a/tests/test_ovfxml.py
+++ /dev/null
@@ -1,81 +0,0 @@
-# Copyright 2014 Microsoft Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# Requires Python 2.4+ and Openssl 1.0+
-#
-# Implements parts of RFC 2131, 1541, 1497 and
-# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
-# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-
-import tests.env
-import tests.tools as tools
-import uuid
-import unittest
-import os
-import json
-from azurelinuxagent.future import text
-import azurelinuxagent.protocol.ovfenv as ovfenv
-
-ExtensionsConfigSample="""\
-<?xml version="1.0" encoding="utf-8"?>
- <Environment xmlns="http://schemas.dmtf.org/ovf/environment/1" xmlns:oe="http://schemas.dmtf.org/ovf/environment/1" xmlns:wa="http://schemas.microsoft.com/windowsazure" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <wa:ProvisioningSection>
- <wa:Version>1.0</wa:Version>
- <LinuxProvisioningConfigurationSet xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
- <ConfigurationSetType>LinuxProvisioningConfiguration</ConfigurationSetType>
- <HostName>HostName</HostName>
- <UserName>UserName</UserName>
- <UserPassword>UserPassword</UserPassword>
- <DisableSshPasswordAuthentication>false</DisableSshPasswordAuthentication>
- <SSH>
- <PublicKeys>
- <PublicKey>
- <Fingerprint>EB0C0AB4B2D5FC35F2F0658D19F44C8283E2DD62</Fingerprint>
- <Path>$HOME/UserName/.ssh/authorized_keys</Path>
- <Value>ssh-rsa AAAANOTAREALKEY== foo@bar.local</Value>
- </PublicKey>
- </PublicKeys>
- <KeyPairs>
- <KeyPair>
- <Fingerprint>EB0C0AB4B2D5FC35F2F0658D19F44C8283E2DD62</Fingerprint>
- <Path>$HOME/UserName/.ssh/id_rsa</Path>
- </KeyPair>
- </KeyPairs>
- </SSH>
- <CustomData>CustomData</CustomData>
- </LinuxProvisioningConfigurationSet>
- </wa:ProvisioningSection>
- </Environment>
-"""
-
-class TestOvf(unittest.TestCase):
- def test_ovf(self):
- config = ovfenv.OvfEnv(ExtensionsConfigSample)
- self.assertEquals("HostName", config.hostname)
- self.assertEquals("UserName", config.username)
- self.assertEquals("UserPassword", config.user_password)
- self.assertEquals(False, config.disable_ssh_password_auth)
- self.assertEquals("CustomData", config.customdata)
- self.assertNotEquals(None, config.ssh_pubkeys)
- self.assertEquals(1, len(config.ssh_pubkeys))
- pubkey = config.ssh_pubkeys[0]
- path, fingerprint, value = pubkey
- self.assertEquals(path, "$HOME/UserName/.ssh/authorized_keys")
- self.assertEquals(fingerprint, "EB0C0AB4B2D5FC35F2F0658D19F44C8283E2DD62"),
- self.assertEquals(value, "ssh-rsa AAAANOTAREALKEY== foo@bar.local")
- self.assertNotEquals(None, config.ssh_keypairs)
- self.assertEquals(1, len(config.ssh_keypairs))
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/test_protocol.py b/tests/test_protocol.py
deleted file mode 100644
index de74443..0000000
--- a/tests/test_protocol.py
+++ /dev/null
@@ -1,72 +0,0 @@
-# Copyright 2014 Microsoft Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# Requires Python 2.4+ and Openssl 1.0+
-#
-# Implements parts of RFC 2131, 1541, 1497 and
-# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
-# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-
-import tests.env
-from tests.tools import *
-import uuid
-import unittest
-import os
-import time
-import json
-from azurelinuxagent.protocol.common import *
-
-extensionDataStr = """
-{
- "vmAgent": {
- "agentVersion": "2.4.1198.689",
- "status": "Ready",
- "message": "GuestAgent is running and accepting new configurations.",
- "extensionHandlers": [{
- "name": "Microsoft.Compute.CustomScript",
- "version": "1.0.0.0",
- "status": "Ready",
- "message": "Plugin enabled (name: Microsoft.Compute.CustomScript, version: 1.0.0.0).",
- "extensions": []
- }]
- }
-}
-"""
-
-class TestProtocolContract(unittest.TestCase):
- def test_get_properties(self):
- data = get_properties(VMInfo())
- data = get_properties(Cert())
- data = get_properties(ExtHandlerPackageList())
- data = get_properties(VMStatus())
- data = get_properties(TelemetryEventList())
- data = get_properties(ExtHandler(name="hehe"))
- self.assertTrue("name" in data)
- self.assertTrue("properties" in data)
- self.assertEquals(dict, type(data["properties"]))
- self.assertTrue("versionUris" in data)
-
- def test_set_properties(self):
- data = json.loads(extensionDataStr)
- obj = VMStatus()
- set_properties("vmStatus", obj, data)
- self.assertNotEquals(None, obj.vmAgent)
- self.assertEquals(VMAgentStatus, type(obj.vmAgent))
- self.assertNotEquals(None, obj.vmAgent.status)
- self.assertNotEquals(None, obj.vmAgent.extensionHandlers)
- self.assertEquals(DataContractList, type(obj.vmAgent.extensionHandlers))
-
-if __name__ == '__main__':
- unittest.main()
-
diff --git a/tests/test_redhat.py b/tests/test_redhat.py
deleted file mode 100644
index d9ea4ec..0000000
--- a/tests/test_redhat.py
+++ /dev/null
@@ -1,49 +0,0 @@
-# Copyright 2014 Microsoft Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# Requires Python 2.4+ and Openssl 1.0+
-#
-# Implements parts of RFC 2131, 1541, 1497 and
-# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
-# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-
-import tests.env
-from tests.tools import *
-import unittest
-from azurelinuxagent.distro.redhat.osutil import RedhatOSUtil
-
-test_pubkey="""\
------BEGIN PUBLIC KEY-----
-MIIBIDANBgkqhkiG9w0BAQEFAAOCAQ0AMIIBCAKCAQEA2wo22vf1N8NWE+5lLfit
-T7uzkfwqdw0IAoHZ0l2BtP0ajy6f835HCR3w3zLWw5ut7Xvyo26x1OMOzjo5lqtM
-h8iyQwfHtWf6Cekxfkf+6Pca99bNuDgwRopOTOyoVgwDzJB0+slpn/sJjeGbhxJl
-ToT8tNPLrBmnnpaMZLMIANcPQtTRCQcV/ycv+/omKXFB+zULYkN8v22o5mysoCuQ
-fzXiJP3Mlnf+V2XMl1WAJylhOJif04K8j+G8oF5ECBIQiph4ZLQS1yTYlozPXU8k
-8vB6A5+UiOGxBnOQYnp42cS5d4qSQ8LORCRGXrCj4DCP+lvkUDLUHx2WN+1ivZkO
-fQIBIw==
------END PUBLIC KEY-----
-"""
-
-expected_ssh_rsa_pubkey="""\
-ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA2wo22vf1N8NWE+5lLfitT7uzkfwqdw0IAoHZ0l2BtP0ajy6f835HCR3w3zLWw5ut7Xvyo26x1OMOzjo5lqtMh8iyQwfHtWf6Cekxfkf+6Pca99bNuDgwRopOTOyoVgwDzJB0+slpn/sJjeGbhxJlToT8tNPLrBmnnpaMZLMIANcPQtTRCQcV/ycv+/omKXFB+zULYkN8v22o5mysoCuQfzXiJP3Mlnf+V2XMl1WAJylhOJif04K8j+G8oF5ECBIQiph4ZLQS1yTYlozPXU8k8vB6A5+UiOGxBnOQYnp42cS5d4qSQ8LORCRGXrCj4DCP+lvkUDLUHx2WN+1ivZkOfQ==
-"""
-
-class TestRedhat(unittest.TestCase):
- def test_RsaPublicKeyToSshRsa(self):
- OSUtil = RedhatOSUtil()
- ssh_rsa_pubkey = OSUtil.asn1_to_ssh_rsa(test_pubkey)
- self.assertEquals(expected_ssh_rsa_pubkey, ssh_rsa_pubkey)
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/test_resourcedisk.py b/tests/test_resourcedisk.py
deleted file mode 100644
index de54fd3..0000000
--- a/tests/test_resourcedisk.py
+++ /dev/null
@@ -1,63 +0,0 @@
-# Copyright 2014 Microsoft Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# Requires Python 2.4+ and Openssl 1.0+
-#
-# Implements parts of RFC 2131, 1541, 1497 and
-# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
-# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-
-import tests.env
-from tests.tools import *
-import unittest
-import azurelinuxagent.distro.default.resourceDisk as rdh
-import azurelinuxagent.logger as logger
-from azurelinuxagent.utils.osutil import OSUTIL
-
-#logger.LoggerInit("/dev/null", "/dev/stdout")
-
-gpt_output_sample="""
-Model: Msft Virtual Disk (scsi)
-Disk /dev/sda: 32.2GB
-Sector size (logical/physical): 512B/4096B
-Partition Table: gpt
-
-Number Start End Size Type File system Flags
- 1 2097kB 29.4GB 29.4GB primary ext4 boot
- 2 2097kB 29.4GB 29.4GB primary ext4 boot
-"""
-
-class TestResourceDisk(unittest.TestCase):
-
- @mock(rdh.OSUTIL, 'device_for_ide_port', MockFunc(retval='foo'))
- @mock(rdh.shellutil, 'run_get_output', MockFunc(retval=(0, gpt_output_sample)))
- @mock(rdh.shellutil, 'run', MockFunc(retval=0))
- def test_mountGPT(self):
- handler = rdh.ResourceDiskHandler()
- handler.mount_resource_disk('/tmp/foo', 'ext4')
-
- @mock(rdh.OSUTIL, 'device_for_ide_port', MockFunc(retval='foo'))
- @mock(rdh.shellutil, 'run_get_output', MockFunc(retval=(0, "")))
- @mock(rdh.shellutil, 'run', MockFunc(retval=0))
- def test_mountMBR(self):
- handler = rdh.ResourceDiskHandler()
- handler.mount_resource_disk('/tmp/foo', 'ext4')
-
- @mock(rdh.shellutil, 'run', MockFunc(retval=0))
- def test_createSwapSpace(self):
- handler = rdh.ResourceDiskHandler()
- handler.create_swap_space('/tmp/foo', 512)
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/test_rest_util.py b/tests/test_rest_util.py
deleted file mode 100644
index d07a1df..0000000
--- a/tests/test_rest_util.py
+++ /dev/null
@@ -1,63 +0,0 @@
-# Copyright 2014 Microsoft Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# Requires Python 2.4+ and Openssl 1.0+
-#
-# Implements parts of RFC 2131, 1541, 1497 and
-# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
-# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-
-import tests.env
-from tests.tools import *
-import uuid
-import unittest
-import os
-import azurelinuxagent.utils.restutil as restutil
-from azurelinuxagent.future import text
-import test
-import socket
-import azurelinuxagent.logger as logger
-
-class MockResponse(object):
- def __init__(self, status=restutil.httpclient.OK):
- self.status = status
-
- def getheaders(self):
- pass
-
-class TestHttpOperations(unittest.TestCase):
-
- def test_parse_url(self):
- host, port, secure, rel_uri = restutil._parse_url("http://abc.def/ghi#hash?jkl=mn")
- self.assertEquals("abc.def", host)
- self.assertEquals("/ghi#hash?jkl=mn", rel_uri)
-
- host, port, secure, rel_uri = restutil._parse_url("http://abc.def/")
- self.assertEquals("abc.def", host)
- self.assertEquals("/", rel_uri)
- self.assertEquals(False, secure)
-
- host, port, secure, rel_uri = restutil._parse_url("https://abc.def/ghi?jkl=mn")
- self.assertEquals(True, secure)
-
- host, port, secure, rel_uri = restutil._parse_url("http://abc.def:80/")
- self.assertEquals("abc.def", host)
-
- @mock(restutil.httpclient.HTTPConnection, 'request', MockFunc())
- @mock(restutil.httpclient.HTTPConnection, 'getresponse', MockFunc(retval=MockResponse()))
- def test_http_request(self):
- restutil.http_get("https://httpbin.org/get")
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/test_v1.py b/tests/test_v1.py
deleted file mode 100644
index 5a1b36b..0000000
--- a/tests/test_v1.py
+++ /dev/null
@@ -1,203 +0,0 @@
-# Copyright 2014 Microsoft Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# Requires Python 2.4+ and Openssl 1.0+
-#
-# Implements parts of RFC 2131, 1541, 1497 and
-# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
-# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-
-import tests.env
-import tests.tools as tools
-from tests.tools import *
-import uuid
-import unittest
-import os
-import time
-from azurelinuxagent.utils.restutil import httpclient
-import azurelinuxagent.logger as logger
-import azurelinuxagent.protocol.v1 as v1
-from tests.test_version import VersionInfoSample
-from tests.test_goalstate import goal_state_sample
-from tests.test_hostingenv import hosting_env_sample
-from tests.test_sharedconfig import shared_config_sample
-from tests.test_certificates import certs_sample, transport_cert
-from tests.test_extensionsconfig import ext_conf_sample, manifest_sample
-
-def mock_fetch_config(self, url, headers=None, chk_proxy=False):
- content = None
- if "versions" in url:
- content = VersionInfoSample
- elif "goalstate" in url:
- content = goal_state_sample
- elif "hostingenvuri" in url:
- content = hosting_env_sample
- elif "sharedconfiguri" in url:
- content = shared_config_sample
- elif "certificatesuri" in url:
- content = certs_sample
- elif "extensionsconfiguri" in url:
- content = ext_conf_sample
- elif "manifest.xml" in url:
- content = manifest_sample
- else:
- raise Exception("Bad url {0}".format(url))
- return content
-
-def mock_fetch_manifest(self, uris):
- return manifest_sample
-
-def mock_fetch_cache(self, file_path):
- content = None
- if "Incarnation" in file_path:
- content = 1
- elif "GoalState" in file_path:
- content = goal_state_sample
- elif "HostingEnvironmentConfig" in file_path:
- content = hosting_env_sample
- elif "SharedConfig" in file_path:
- content = shared_config_sample
- elif "Certificates" in file_path:
- content = certs_sample
- elif "TransportCert" in file_path:
- content = transport_cert
- elif "ExtensionsConfig" in file_path:
- content = ext_conf_sample
- elif "manifest" in file_path:
- content = manifest_sample
- else:
- raise Exception("Bad filepath {0}".format(file_path))
- return content
-
-data_with_bom = b'\xef\xbb\xbfhehe'
-
-class MockResp(object):
- def __init__(self, status=v1.httpclient.OK, data=None):
- self.status = status
- self.data = data
-
- def read(self):
- return self.data
-
-def mock_403():
- return MockResp(status = v1.httpclient.FORBIDDEN)
-
-def mock_410():
- return MockResp(status = v1.httpclient.GONE)
-
-def mock_503():
- return MockResp(status = v1.httpclient.SERVICE_UNAVAILABLE)
-
-class TestWireClint(unittest.TestCase):
-
- @mock(v1.restutil, 'http_get', MockFunc(retval=MockResp(data=data_with_bom)))
- def test_fetch_uri_with_bom(self):
- client = v1.WireClient("http://foo.bar/")
- client.fetch_config("http://foo.bar", None)
-
- @mock(v1.WireClient, 'fetch_cache', mock_fetch_cache)
- def test_get(self):
- os.chdir('/tmp')
- client = v1.WireClient("foobar")
- goalState = client.get_goal_state()
- self.assertNotEquals(None, goalState)
- hostingEnv = client.get_hosting_env()
- self.assertNotEquals(None, hostingEnv)
- sharedConfig = client.get_shared_conf()
- self.assertNotEquals(None, sharedConfig)
- extensionsConfig = client.get_ext_conf()
- self.assertNotEquals(None, extensionsConfig)
-
-
- @mock(v1.WireClient, 'fetch_cache', mock_fetch_cache)
- def test_get_head_for_cert(self):
- client = v1.WireClient("foobar")
- header = client.get_header_for_cert()
- self.assertNotEquals(None, header)
-
- @mock(v1.WireClient, 'get_header_for_cert', MockFunc())
- @mock(v1.WireClient, 'fetch_config', mock_fetch_config)
- @mock(v1.WireClient, 'fetch_manifest', mock_fetch_manifest)
- @mock(v1.fileutil, 'write_file', MockFunc())
- def test_update_goal_state(self):
- client = v1.WireClient("foobar")
- client.update_goal_state()
- goal_state = client.get_goal_state()
- self.assertNotEquals(None, goal_state)
- hosting_env = client.get_hosting_env()
- self.assertNotEquals(None, hosting_env)
- shared_config = client.get_shared_conf()
- self.assertNotEquals(None, shared_config)
- ext_conf = client.get_ext_conf()
- self.assertNotEquals(None, ext_conf)
-
- @mock(v1.time, "sleep", MockFunc())
- def test_call_wireserver(self):
- client = v1.WireClient("foobar")
- self.assertRaises(v1.ProtocolError, client.call_wireserver, mock_403)
- self.assertRaises(v1.WireProtocolResourceGone, client.call_wireserver,
- mock_410)
-
- @mock(v1.time, "sleep", MockFunc())
- def test_call_storage_service(self):
- client = v1.WireClient("foobar")
- self.assertRaises(v1.ProtocolError, client.call_storage_service,
- mock_503)
-
-
-class TestStatusBlob(unittest.TestCase):
- def testToJson(self):
- vm_status = v1.VMStatus()
- status_blob = v1.StatusBlob(v1.WireClient("http://foo.bar/"))
- status_blob.set_vm_status(vm_status)
- self.assertNotEquals(None, status_blob.to_json())
-
- @mock(v1.restutil, 'http_put', MockFunc(retval=MockResp(httpclient.CREATED)))
- @mock(v1.restutil, 'http_head', MockFunc(retval=MockResp(httpclient.OK)))
- def test_put_page_blob(self):
- vm_status = v1.VMStatus()
- status_blob = v1.StatusBlob(v1.WireClient("http://foo.bar/"))
- status_blob.set_vm_status(vm_status)
- data = 'a' * 100
- status_blob.put_page_blob("http://foo.bar", data)
-
-class TestConvert(unittest.TestCase):
- def test_status(self):
- vm_status = v1.VMStatus()
- handler_status = v1.ExtHandlerStatus(name="foo")
-
- ext_statuses = {}
-
- ext_name="bar"
- ext_status = v1.ExtensionStatus()
- handler_status.extensions.append(ext_name)
- ext_statuses[ext_name] = ext_status
-
- substatus = v1.ExtensionSubStatus()
- ext_status.substatusList.append(substatus)
-
- vm_status.vmAgent.extensionHandlers.append(handler_status)
- v1_status = v1.vm_status_to_v1(vm_status, ext_statuses)
- print(v1_status)
-
- def test_param(self):
- param = v1.TelemetryEventParam()
- event = v1.TelemetryEvent()
- event.parameters.append(param)
-
- v1.event_to_v1(event)
-
-if __name__ == '__main__':
- unittest.main()
-
diff --git a/tests/test_v2.py b/tests/test_v2.py
deleted file mode 100644
index c4a0b4d..0000000
--- a/tests/test_v2.py
+++ /dev/null
@@ -1,120 +0,0 @@
-# Copyright 2014 Microsoft Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# Requires Python 2.4+ and Openssl 1.0+
-#
-# Implements parts of RFC 2131, 1541, 1497 and
-# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
-# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-
-import tests.env
-from tests.tools import *
-import unittest
-import json
-import azurelinuxagent.protocol.v2 as v2
-
-SAMPLE_IDENTITY=u"""{
- "vmName":"foo",
- "subscriptionId":"bar"
-}"""
-
-SAMPLE_CERTS=u"""{
- "certificates":[{
- "name":"foo",
- "thumbprint":"bar",
- "certificateDataUri":"baz"
- }]
-}"""
-
-SAMPLE_EXT_HANDLER=u"""[{
- "name":"foo",
- "properties":{
- "version":"bar",
- "upgradePolicy": "manual",
- "state": "enabled",
- "extensions":[{
- "name":"baz",
- "sequenceNumber":0,
- "publicSettings":{
- "commandToExecute": "echo 123",
- "uris":[]
- }
- }]
- },
- "versionUris":[{
- "uri":"versionUri.foo"
- }]
-}]"""
-
-SAMPLE_EXT_HANDLER_PKGS=u"""{
- "versions": [{
- "version":"foo",
- "uris":[{
- "uri":"bar"
- },{
- "uri":"baz"
- }]
- }]
-}"""
-
-def mock_get_data(self, url, headers=None):
- data = u"{}"
- if url.count(u"identity") > 0:
- data = SAMPLE_IDENTITY
- elif url.count(u"certificates") > 0:
- data = SAMPLE_CERTS
- elif url.count(u"extensionHandlers") > 0:
- data = SAMPLE_EXT_HANDLER
- elif url.count(u"versionUri") > 0:
- data = SAMPLE_EXT_HANDLER_PKGS
- return json.loads(data)
-
-class TestMetadataProtocol(unittest.TestCase):
- @mock(v2.MetadataProtocol, '_get_data', mock_get_data)
- def test_getters(self):
- protocol = v2.MetadataProtocol()
- vminfo = protocol.get_vminfo()
- self.assertNotEquals(None, vminfo)
- self.assertNotEquals(None, vminfo.vmName)
- self.assertNotEquals(None, vminfo.subscriptionId)
-
- protocol.get_certs()
-
- ext_handers = protocol.get_ext_handlers()
- self.assertNotEquals(None, ext_handers)
- self.assertNotEquals(None, ext_handers.extHandlers)
- self.assertNotEquals(0, len(ext_handers.extHandlers))
-
- ext_hander = ext_handers.extHandlers[0]
- self.assertNotEquals(None, ext_hander)
- self.assertNotEquals(0, len(ext_hander.properties.extensions))
-
- ext = ext_hander.properties.extensions[0]
- self.assertNotEquals(None, ext)
- self.assertNotEquals(None, ext.publicSettings)
- self.assertEquals("echo 123", ext.publicSettings.get('commandToExecute'))
-
- packages = protocol.get_ext_handler_pkgs(ext_handers.extHandlers[0])
- self.assertNotEquals(None, packages)
-
- @mock(v2.MetadataProtocol, '_put_data', MockFunc())
- def test_reporters(self):
- protocol = v2.MetadataProtocol()
- protocol.report_provision_status(v2.ProvisionStatus())
- protocol.report_vm_status(v2.VMStatus())
- protocol.report_ext_status("foo", "baz", v2.ExtensionStatus())
- protocol.report_event(v2.TelemetryEventList())
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/test_version.py b/tests/test_version.py
deleted file mode 100644
index 72d9599..0000000
--- a/tests/test_version.py
+++ /dev/null
@@ -1,53 +0,0 @@
-# Copyright 2014 Microsoft Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# Requires Python 2.4+ and Openssl 1.0+
-#
-# Implements parts of RFC 2131, 1541, 1497 and
-# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
-# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-
-import tests.env
-import tests.tools as tools
-import uuid
-import unittest
-import os
-import json
-import azurelinuxagent.protocol.v1 as v1
-from azurelinuxagent.future import text
-
-VersionInfoSample=u"""\
-<?xml version="1.0" encoding="utf-8"?>
-<Versions>
- <Preferred>
- <Version>2012-11-30</Version>
- </Preferred>
- <Supported>
- <Version>2010-12-15</Version>
- <Version>2010-28-10</Version>
- </Supported>
-</Versions>
-"""
-
-class TestVersionInfo(unittest.TestCase):
- def test_version_info(self):
- config = v1.VersionInfo(VersionInfoSample)
- self.assertEquals("2012-11-30", config.get_preferred())
- self.assertNotEquals(None, config.get_supported())
- self.assertEquals(2, len(config.get_supported()))
- self.assertEquals("2010-12-15", config.get_supported()[0])
- self.assertEquals("2010-28-10", config.get_supported()[1])
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/tools.py b/tests/tools.py
index 392f395..672c60b 100644
--- a/tests/tools.py
+++ b/tests/tools.py
@@ -18,48 +18,107 @@
# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
+"""
+Define util functions for unit test
+"""
+import re
import os
import sys
+import unittest
+import shutil
+import json
+import tempfile
from functools import wraps
-from azurelinuxagent.utils.osutil import OSUTIL
-
-parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
-sys.path.append(parent)
-
-def simple_file_grep(file_path, search_str):
- for line in open(file_path):
- if search_str in line:
- return line
-
-def mock(target, name, mock):
- def decorator(func):
- @wraps(func)
- def wrapper(*args, **kwargs):
- origin = getattr(target, name)
- setattr(target, name, mock)
- try:
- result = func(*args, **kwargs)
- except:
- raise
- finally:
- setattr(target, name, origin)
- return result
- return wrapper
- return decorator
+import azurelinuxagent.conf as conf
+import azurelinuxagent.logger as logger
+import azurelinuxagent.event as event
+
+#Import mock module for Python2 and Python3
+try:
+ from unittest.mock import Mock, patch, MagicMock
+except ImportError:
+ from mock import Mock, patch, MagicMock
+
+test_dir = os.path.dirname(os.path.abspath(__file__))
+data_dir = os.path.join(test_dir, "data")
+
+debug = False
+if os.environ.get('DEBUG') == '1':
+ debug = True
+
+#Enable verbose logger to stdout
+if debug:
+ logger.add_logger_appender(logger.AppenderType.STDOUT,
+ logger.LogLevel.VERBOSE)
+
+class AgentTestCase(unittest.TestCase):
+ def setUp(self):
+ prefix = "{0}_".format(self.__class__.__name__)
+ self.tmp_dir = tempfile.mkdtemp(prefix=prefix)
+ conf.get_lib_dir = Mock(return_value=self.tmp_dir)
+ ext_log_dir = os.path.join(self.tmp_dir, "azure")
+ conf.get_ext_log_dir = Mock(return_value=ext_log_dir)
+
+ def tearDown(self):
+ if not debug and self.tmp_dir is not None:
+ shutil.rmtree(self.tmp_dir)
+
+def load_data(name):
+ """Load test data"""
+ path = os.path.join(data_dir, name)
+ with open(path, "r") as data_file:
+ return data_file.read()
-class MockFunc(object):
- def __init__(self, name='', retval=None):
- self.name = name
- self.retval = retval
+def load_bin_data(name):
+ """Load test bin data"""
+ path = os.path.join(data_dir, name)
+ with open(path, "rb") as data_file:
+ return data_file.read()
- def __call__(*args, **kwargs):
- self = args[0]
- self.args = args[1:]
- self.kwargs = kwargs
- return self.retval
+
+supported_distro = [
+ ["ubuntu", "12.04", ""],
+ ["ubuntu", "14.04", ""],
+ ["ubuntu", "14.10", ""],
+ ["ubuntu", "15.10", ""],
+ ["ubuntu", "15.10", "Snappy Ubuntu Core"],
+
+ ["coreos", "", ""],
+
+ ["suse", "12", "SUSE Linux Enterprise Server"],
+ ["suse", "13.2", "openSUSE"],
+ ["suse", "11", "SUSE Linux Enterprise Server"],
+ ["suse", "13.1", "openSUSE"],
+
+ ["debian", "6.0", ""],
+
+ ["redhat", "6.5", ""],
+ ["redhat", "7.0", ""],
+
+]
+
+def distros(distro_name=".*", distro_version=".*", distro_full_name=".*"):
+ """Run test on multiple distros"""
+ def decorator(test_method):
+ @wraps(test_method)
+ def wrapper(self, *args, **kwargs):
+ for distro in supported_distro:
+ if re.match(distro_name, distro[0]) and \
+ re.match(distro_version, distro[1]) and \
+ re.match(distro_full_name, distro[2]):
+ if debug:
+ logger.info("Run {0} on {1}", test_method.__name__,
+ distro)
+ new_args = []
+ new_args.extend(args)
+ new_args.extend(distro)
+ test_method(self, *new_args, **kwargs)
+ #Call tearDown and setUp to create seprated environment for
+ #distro testing
+ self.tearDown()
+ self.setUp()
+ return wrapper
+ return decorator
-#Mock osutil so that the test of other part will be os unrelated
-OSUTIL.get_lib_dir = MockFunc(retval='/tmp')
-OSUTIL.get_ext_log_dir = MockFunc(retval='/tmp/log')
diff --git a/tests/utils/__init__.py b/tests/utils/__init__.py
new file mode 100644
index 0000000..9bdb27e
--- /dev/null
+++ b/tests/utils/__init__.py
@@ -0,0 +1,19 @@
+# Copyright 2014 Microsoft Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Requires Python 2.4+ and Openssl 1.0+
+#
+# Implements parts of RFC 2131, 1541, 1497 and
+# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
+# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
diff --git a/tests/test_file_util.py b/tests/utils/test_file_util.py
index 1eeb784..bf7c638 100644
--- a/tests/test_file_util.py
+++ b/tests/utils/test_file_util.py
@@ -18,48 +18,48 @@
# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-import tests.env
-import tests.tools as tools
+from tests.tools import *
import uuid
import unittest
import os
import sys
-from azurelinuxagent.future import text
+from azurelinuxagent.future import ustr
import azurelinuxagent.utils.fileutil as fileutil
-class TestFileOperations(unittest.TestCase):
+class TestFileOperations(AgentTestCase):
def test_read_write_file(self):
- test_file='/tmp/test_file'
- content = text(uuid.uuid4())
+ test_file=os.path.join(self.tmp_dir, 'test_file')
+ content = ustr(uuid.uuid4())
fileutil.write_file(test_file, content)
- self.assertTrue(tools.simple_file_grep(test_file, content))
- content_read = fileutil.read_file('/tmp/test_file')
+ content_read = fileutil.read_file(test_file)
self.assertEquals(content, content_read)
os.remove(test_file)
def test_rw_utf8_file(self):
- test_file='/tmp/test_file3'
- content = "\u6211"
+ test_file=os.path.join(self.tmp_dir, 'test_file')
+ content = u"\u6211"
fileutil.write_file(test_file, content, encoding="utf-8")
- self.assertTrue(tools.simple_file_grep(test_file, content))
- content_read = fileutil.read_file('/tmp/test_file3')
+ content_read = fileutil.read_file(test_file)
self.assertEquals(content, content_read)
os.remove(test_file)
def test_remove_bom(self):
- test_file= '/tmp/test_file4'
+ test_file=os.path.join(self.tmp_dir, 'test_file')
data = b'\xef\xbb\xbfhehe'
fileutil.write_file(test_file, data, asbin=True)
data = fileutil.read_file(test_file, remove_bom=True)
self.assertNotEquals(0xbb, ord(data[0]))
def test_append_file(self):
- test_file='/tmp/test_file2'
- content = text(uuid.uuid4())
+ test_file=os.path.join(self.tmp_dir, 'test_file')
+ content = ustr(uuid.uuid4())
fileutil.append_file(test_file, content)
- self.assertTrue(tools.simple_file_grep(test_file, content))
+
+ content_read = fileutil.read_file(test_file)
+ self.assertEquals(content, content_read)
+
os.remove(test_file)
def test_get_last_path_element(self):
diff --git a/tests/utils/test_rest_util.py b/tests/utils/test_rest_util.py
new file mode 100644
index 0000000..bd22c55
--- /dev/null
+++ b/tests/utils/test_rest_util.py
@@ -0,0 +1,126 @@
+# Copyright 2014 Microsoft Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Requires Python 2.4+ and Openssl 1.0+
+#
+# Implements parts of RFC 2131, 1541, 1497 and
+# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
+# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
+
+from tests.tools import AgentTestCase, patch, Mock, MagicMock
+import uuid
+import unittest
+import os
+import azurelinuxagent.utils.restutil as restutil
+from azurelinuxagent.future import ustr, httpclient
+import azurelinuxagent.logger as logger
+
+class TestHttpOperations(AgentTestCase):
+
+ def test_parse_url(self):
+ test_uri = "http://abc.def/ghi#hash?jkl=mn"
+ host, port, secure, rel_uri = restutil._parse_url(test_uri)
+ self.assertEquals("abc.def", host)
+ self.assertEquals("/ghi#hash?jkl=mn", rel_uri)
+
+ test_uri = "http://abc.def/"
+ host, port, secure, rel_uri = restutil._parse_url(test_uri)
+ self.assertEquals("abc.def", host)
+ self.assertEquals("/", rel_uri)
+ self.assertEquals(False, secure)
+
+ test_uri = "https://abc.def/ghi?jkl=mn"
+ host, port, secure, rel_uri = restutil._parse_url(test_uri)
+ self.assertEquals(True, secure)
+
+ test_uri = "http://abc.def:80/"
+ host, port, secure, rel_uri = restutil._parse_url(test_uri)
+ self.assertEquals("abc.def", host)
+
+ host, port, secure, rel_uri = restutil._parse_url("")
+ self.assertEquals(None, host)
+ self.assertEquals(rel_uri, "")
+
+ host, port, secure, rel_uri = restutil._parse_url("None")
+ self.assertEquals(None, host)
+ self.assertEquals(rel_uri, "None")
+
+
+ @patch("azurelinuxagent.future.httpclient.HTTPSConnection")
+ @patch("azurelinuxagent.future.httpclient.HTTPConnection")
+ def test_http_request(self, HTTPConnection, HTTPSConnection):
+ mock_httpconn = MagicMock()
+ mock_httpresp = MagicMock()
+ mock_httpconn.getresponse = Mock(return_value=mock_httpresp)
+ HTTPConnection.return_value = mock_httpconn
+ HTTPSConnection.return_value = mock_httpconn
+
+ mock_httpresp.read = Mock(return_value="_(:3| <)_")
+
+ #Test http get
+ resp = restutil._http_request("GET", "foo", "bar")
+ self.assertNotEquals(None, resp)
+ self.assertEquals("_(:3| <)_", resp.read())
+
+ #Test https get
+ resp = restutil._http_request("GET", "foo", "bar", secure=True)
+ self.assertNotEquals(None, resp)
+ self.assertEquals("_(:3| <)_", resp.read())
+
+ #Test http get with proxy
+ mock_httpresp.read = Mock(return_value="_(:3| <)_")
+ resp = restutil._http_request("GET", "foo", "bar", proxy_host="foo.bar",
+ proxy_port=23333)
+ self.assertNotEquals(None, resp)
+ self.assertEquals("_(:3| <)_", resp.read())
+
+ #Test https get
+ resp = restutil._http_request("GET", "foo", "bar", secure=True)
+ self.assertNotEquals(None, resp)
+ self.assertEquals("_(:3| <)_", resp.read())
+
+ #Test https get with proxy
+ mock_httpresp.read = Mock(return_value="_(:3| <)_")
+ resp = restutil._http_request("GET", "foo", "bar", proxy_host="foo.bar",
+ proxy_port=23333, secure=True)
+ self.assertNotEquals(None, resp)
+ self.assertEquals("_(:3| <)_", resp.read())
+
+ @patch("time.sleep")
+ @patch("azurelinuxagent.utils.restutil._http_request")
+ def test_http_request_with_retry(self, _http_request, sleep):
+ mock_httpresp = MagicMock()
+ mock_httpresp.read = Mock(return_value="hehe")
+ _http_request.return_value = mock_httpresp
+
+ #Test http get
+ resp = restutil.http_get("http://foo.bar")
+ self.assertEquals("hehe", resp.read())
+
+ #Test https get
+ resp = restutil.http_get("https://foo.bar")
+ self.assertEquals("hehe", resp.read())
+
+ #Test http failure
+ _http_request.side_effect = httpclient.HTTPException("Http failure")
+ self.assertRaises(restutil.HttpError, restutil.http_get, "http://foo.bar")
+
+ #Test http failure
+ _http_request.side_effect = IOError("IO failure")
+ self.assertRaises(restutil.HttpError, restutil.http_get, "http://foo.bar")
+
+if __name__ == '__main__':
+ unittest.main()
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tests/test_shell_util.py b/tests/utils/test_shell_util.py
index 9f84c6d..aa89121 100644
--- a/tests/test_shell_util.py
+++ b/tests/utils/test_shell_util.py
@@ -19,16 +19,14 @@
# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-import tests.env
-import tests.tools as tools
+from tests.tools import *
import uuid
import unittest
import os
import azurelinuxagent.utils.shellutil as shellutil
import test
-from azurelinuxagent.future import text
-class TestrunCmd(unittest.TestCase):
+class TestrunCmd(AgentTestCase):
def test_run_get_output(self):
output = shellutil.run_get_output(u"ls /")
self.assertNotEquals(None, output)
diff --git a/tests/test_text_util.py b/tests/utils/test_text_util.py
index 5c0016c..0e8cc7d 100644
--- a/tests/test_text_util.py
+++ b/tests/utils/test_text_util.py
@@ -18,16 +18,15 @@
# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
-import tests.env
from tests.tools import *
import uuid
import unittest
import os
-from azurelinuxagent.future import text
+from azurelinuxagent.future import ustr
import azurelinuxagent.utils.textutil as textutil
from azurelinuxagent.utils.textutil import Version
-class TestTextUtil(unittest.TestCase):
+class TestTextUtil(AgentTestCase):
def test_get_password_hash(self):
password_hash = textutil.gen_password_hash("asdf", 6, 10)
self.assertNotEquals(None, password_hash)
@@ -36,7 +35,7 @@ class TestTextUtil(unittest.TestCase):
def test_remove_bom(self):
#Test bom could be removed
- data = text(b'\xef\xbb\xbfhehe', encoding='utf-8')
+ data = ustr(b'\xef\xbb\xbfhehe', encoding='utf-8')
data = textutil.remove_bom(data)
self.assertNotEquals(0xbb, data[0])
@@ -45,7 +44,7 @@ class TestTextUtil(unittest.TestCase):
data = textutil.remove_bom(data)
self.assertEquals(u"h", data[0])
- def test_version_compare(self) :
+ def test_version_compare(self):
self.assertTrue(Version("1.0") < Version("1.1"))
self.assertTrue(Version("1.9") < Version("1.10"))
self.assertTrue(Version("1.9.9") < Version("1.10.0"))
@@ -61,6 +60,20 @@ class TestTextUtil(unittest.TestCase):
self.assertTrue(Version("1.9") < "1.10")
self.assertTrue("1.9" < Version("1.10"))
+
+ def test_get_bytes_from_pem(self):
+ content = ("-----BEGIN CERTIFICATE-----\n"
+ "certificate\n"
+ "-----END CERTIFICATE----\n")
+ base64_bytes = textutil.get_bytes_from_pem(content)
+ self.assertEquals("certificate", base64_bytes)
+
+
+ content = ("-----BEGIN PRIVATE KEY-----\n"
+ "private key\n"
+ "-----END PRIVATE Key-----\n")
+ base64_bytes = textutil.get_bytes_from_pem(content)
+ self.assertEquals("private key", base64_bytes)
if __name__ == '__main__':
unittest.main()