From 9f299a419fc93ce4604984480207fafa52265f3f Mon Sep 17 00:00:00 2001 From: Yue Zhang Date: Tue, 30 Jun 2015 13:18:13 +0800 Subject: [PATCH] Improve log and cleanup code --- azurelinuxagent/agent.py | 7 +---- azurelinuxagent/distro/default/dhcp.py | 9 +++++-- azurelinuxagent/distro/default/extension.py | 2 -- azurelinuxagent/distro/default/osutil.py | 11 ++------ azurelinuxagent/distro/default/provision.py | 16 ++++++++--- azurelinuxagent/distro/default/run.py | 8 +++--- azurelinuxagent/distro/ubuntu/loader.py | 2 +- azurelinuxagent/distro/ubuntu/provision.py | 3 ++- azurelinuxagent/protocol/protocolFactory.py | 1 + azurelinuxagent/protocol/v1.py | 1 - bin/azurela | 30 --------------------- config/suse/waagent.conf | 2 ++ config/ubuntu/waagent.conf | 2 ++ config/waagent.conf | 5 ++-- init/waagent | 3 +++ setup.py | 2 +- 16 files changed, 41 insertions(+), 63 deletions(-) delete mode 100755 bin/azurela diff --git a/azurelinuxagent/agent.py b/azurelinuxagent/agent.py index 6bae350..c685825 100644 --- a/azurelinuxagent/agent.py +++ b/azurelinuxagent/agent.py @@ -58,8 +58,6 @@ def ParseArgs(sysArgv): cmd = "start" elif re.match("^([-/]*)version", a): cmd = "version" - elif re.match("^([-/]*)serialconsole", a): - cmd = "serialconsole" elif re.match("^([-/]*)verbose", a): verbose = True elif re.match("^([-/]*)force", a): @@ -77,7 +75,7 @@ def Version(): def Usage(): print("") print(("usage: {0} [-verbose] [-force] " - "[-help|-deprovision[+user]|-version|-serialconsole|-daemon|-start]" + "[-help|-deprovision[+user]|-version|-daemon|-start]" "").format(sys.argv[0])) print("") @@ -93,9 +91,6 @@ def Main(): Usage() else: Init(verbose) - if command == "serialconsole": - #TODO - pass if command == "deprovision+user": Deprovision(force, deluser=True) elif command == "deprovision": diff --git a/azurelinuxagent/distro/default/dhcp.py b/azurelinuxagent/distro/default/dhcp.py index bfb86e4..8cac39f 100644 --- a/azurelinuxagent/distro/default/dhcp.py +++ b/azurelinuxagent/distro/default/dhcp.py @@ -42,12 +42,16 @@ class DhcpHandler(object): ipv4 = OSUtil.GetIpv4Address() def probe(self): + logger.Info("Send dhcp request") self.waitForNetwork() macAddress = OSUtil.GetMacAddress() req = BuildDhcpRequest(macAddress) resp = SendDhcpRequest(req) endpoint, gateway, routes = ParseDhcpResponse(resp) self.endpoint = endpoint + logger.Info("Wire server endpoint:{0}", endpoint) + logger.Info("Gateway:{0}", gateway) + logger.Info("Routes:{0}", routes) if endpoint is not None: path = os.path.join(OSUtil.GetLibDir(), WireServerAddrFile) fileutil.SetFileContents(path, endpoint) @@ -59,6 +63,7 @@ class DhcpHandler(object): return self.endpoint def configRoutes(self): + logger.Info("Configure routes") #Add default gateway if self.gateway is not None: OSUtil.RouteAdd(0 , 0, self.gateway) @@ -246,8 +251,8 @@ def SocketSend(request): sock.bind(("0.0.0.0", 68)) sock.sendto(request, ("", 67)) sock.settimeout(10) - logger.Info("Send DHCP request: Setting socket.timeout=10, " - "entering recv") + logger.Verbose("Send DHCP request: Setting socket.timeout=10, " + "entering recv") response = sock.recv(1024) return response diff --git a/azurelinuxagent/distro/default/extension.py b/azurelinuxagent/distro/default/extension.py index 46c7bfc..410436e 100644 --- a/azurelinuxagent/distro/default/extension.py +++ b/azurelinuxagent/distro/default/extension.py @@ -72,7 +72,6 @@ def extension_status_to_v2(extStatus, seqNo): validate_has_key(extStatus['status'], 'status', 'status/status') validate_has_key(extStatus['status'], 'operation', 'status/operation') validate_has_key(extStatus['status'], 'code', 'status/code') - #TODO are those fields all mandatory validate_has_key(extStatus['status'], 'name', 'status/name') validate_has_key(extStatus['status'], 'formattedMessage', 'status/formattedMessage') @@ -218,7 +217,6 @@ class ExtensionInstance(object): elif targetVersion == self.currVersion: self.enable() else: - #TODO downgrade is not allowed? raise ExtensionError("A newer version has already been installed") else: if targetVersion > self.getVersion(): diff --git a/azurelinuxagent/distro/default/osutil.py b/azurelinuxagent/distro/default/osutil.py index 0e3162f..67c0257 100644 --- a/azurelinuxagent/distro/default/osutil.py +++ b/azurelinuxagent/distro/default/osutil.py @@ -315,8 +315,6 @@ class DefaultOSUtil(object): def MountDvd(self, maxRetry=6, chk_err=True): dvd = self.GetDvdDevice() mountPoint = self.GetDvdMountPoint() - #TODO Why do we need to load atapiix? - #self.LoadAtapiixModule() mountlist = shellutil.RunGetOutput("mount")[1] existing = self.GetMountPoint(mountlist, dvd) if existing is not None: #Already mounted @@ -329,7 +327,7 @@ class DefaultOSUtil(object): retcode = self.Mount(dvd, mountPoint, option="-o ro -t iso9660,udf", chk_err=chk_err) if retcode == 0: - logger.Info("Successfully mounted provision dvd") + logger.Info("Successfully mounted dvd") return if retry < maxRetry - 1: logger.Warn("Mount dvd failed: retry={0}, ret={1}", retry, @@ -418,10 +416,6 @@ class DefaultOSUtil(object): logger.Warn("Move rules file {0} to {1}", fileName, dest) shutil.move(src, dest) - def CheckDependencies(self): - #TODO Add dependency check - pass - def GetMacAddress(self): """ Convienience function, returns mac addr bound to @@ -571,8 +565,7 @@ class DefaultOSUtil(object): if original != timeout: fileutil.SetFileContents(filePath, timeout) logger.Info("Set block dev timeout: {0} with timeout: {1}", - dev, - timeout) + dev, timeout) def GetMountPoint(self, mountlist, device): """ diff --git a/azurelinuxagent/distro/default/provision.py b/azurelinuxagent/distro/default/provision.py index 5d43a51..cf7149e 100644 --- a/azurelinuxagent/distro/default/provision.py +++ b/azurelinuxagent/distro/default/provision.py @@ -40,7 +40,7 @@ class ProvisionHandler(object): if os.path.isfile(provisioned): return - logger.Info("Start provisioning.") + logger.Info("Run provision handler.") protocol = prot.Factory.getDefaultProtocol() try: status = prot.ProvisionStatus(status="NotReady", @@ -85,6 +85,7 @@ class ProvisionHandler(object): def provision(self): + logger.Info("Copy ovf-env.xml.") try: ovfenv = ovf.CopyOvfEnv() except prot.ProtocolError as e: @@ -92,24 +93,29 @@ class ProvisionHandler(object): password = ovfenv.getUserPassword() ovfenv.clearUserPassword() - + + logger.Info("Set host name.") OSUtil.SetHostname(ovfenv.getComputerName()) + logger.Info("Publish host name.") OSUtil.PublishHostname(ovfenv.getComputerName()) + logger.Info("Create user account.") OSUtil.UpdateUserAccount(ovfenv.getUserName(), password) if password is not None: userSalt = conf.GetSwitch("Provision.UseSalt", True) saltType = conf.GetSwitch("Provision.SaltType", 6) + logger.Info("Set user password.") OSUtil.ChangePassword(ovfenv.getUserName(), password, userSalt, saltType) + logger.Info("Configure sshd.") OSUtil.ConfigSshd(ovfenv.getDisableSshPasswordAuthentication()) #Disable selinux temporary sel = OSUtil.IsSelinuxRunning() if sel: OSUtil.SetSelinuxEnforce(0) - + self.deploySshPublicKeys(ovfenv) self.deploySshKeyPairs(ovfenv) self.saveCustomData(ovfenv) @@ -124,19 +130,21 @@ class ProvisionHandler(object): def saveCustomData(self, ovfenv): + logger.Info("Save custom data") customData = ovfenv.getCustomData() if customData is None: return - #TODO port Abel's fix to decoding custom data libDir = OSUtil.GetLibDir() fileutil.SetFileContents(os.path.join(libDir, CustomDataFile), OSUtil.TranslateCustomData(customData)) def deploySshPublicKeys(self, ovfenv): for thumbprint, path in ovfenv.getSshPublicKeys(): + logger.Info("Deploy ssh public key.") OSUtil.DeploySshPublicKey(ovfenv.getUserName(), thumbprint, path) def deploySshKeyPairs(self, ovfenv): for thumbprint, path in ovfenv.getSshKeyPairs(): + logger.Info("Deploy ssh key pairs.") OSUtil.DeploySshKeyPair(ovfenv.getUserName(), thumbprint, path) diff --git a/azurelinuxagent/distro/default/run.py b/azurelinuxagent/distro/default/run.py index e92a9f0..b654af8 100644 --- a/azurelinuxagent/distro/default/run.py +++ b/azurelinuxagent/distro/default/run.py @@ -40,9 +40,10 @@ class RunHandler(object): event.EnableUnhandledErrorDump("Azure Linux Agent") fileutil.SetFileContents(OSUtil.GetAgentPidPath(), str(os.getpid())) - - if self.handlers.scvmmHandler.detectScvmmEnv(): - return + + if conf.GetSwitch("DetectScvmmEnv", False): + if self.handlers.scvmmHandler.detectScvmmEnv(): + return self.handlers.dhcpHandler.probe() @@ -71,6 +72,7 @@ class RunHandler(object): for handlerStatus in handlerStatusList: vmStatus.extensionHandlers.append(handlerStatus) try: + logger.Info("Report vm status") protocol.reportStatus(vmStatus) except prot.ProtocolError as e: logger.Error("Failed to report vm status: {0}", e) diff --git a/azurelinuxagent/distro/ubuntu/loader.py b/azurelinuxagent/distro/ubuntu/loader.py index f7e071e..811ddbe 100644 --- a/azurelinuxagent/distro/ubuntu/loader.py +++ b/azurelinuxagent/distro/ubuntu/loader.py @@ -25,7 +25,7 @@ def GetOSUtil(): Ubuntu14xOSUtil if DistroVersion == "12.04": return Ubuntu1204OSUtil() - elif DistroVersion == "14.04" 0r DistroVersion == "14.10": + elif DistroVersion == "14.04" or DistroVersion == "14.10": return Ubuntu14xOSUtil() else: return UbuntuOSUtil() diff --git a/azurelinuxagent/distro/ubuntu/provision.py b/azurelinuxagent/distro/ubuntu/provision.py index 4c2f022..20a11f9 100644 --- a/azurelinuxagent/distro/ubuntu/provision.py +++ b/azurelinuxagent/distro/ubuntu/provision.py @@ -33,12 +33,12 @@ On ubuntu image, provision could be disabled. """ class UbuntuProvisionHandler(ProvisionHandler): def process(self): - logger.Info("Run ubuntu provision handler") #If provision is enabled, run default provision handler if conf.GetSwitch("Provisioning.Enabled", False): super(UbuntuProvisionHandler, self).process() return + logger.Info("Run Ubuntu provision handler") provisioned = os.path.join(OSUtil.GetLibDir(), "provisioned") if os.path.isfile(provisioned): return @@ -46,6 +46,7 @@ class UbuntuProvisionHandler(ProvisionHandler): logger.Info("Waiting cloud-init to finish provisioning.") protocol = prot.Factory.getDefaultProtocol() try: + logger.Info("Wait for ssh host key to be generated.") thumbprint = self.waitForSshHostKey() fileutil.SetFileContents(provisioned, "") diff --git a/azurelinuxagent/protocol/protocolFactory.py b/azurelinuxagent/protocol/protocolFactory.py index 775ce9b..59a73af 100644 --- a/azurelinuxagent/protocol/protocolFactory.py +++ b/azurelinuxagent/protocol/protocolFactory.py @@ -75,6 +75,7 @@ def DetectAvailableProtocols(probeFuncs=[DetectV1, DetectV2]): return availableProtocols def DetectDefaultProtocol(): + logger.Info("Detect default protocol.") availableProtocols = DetectAvailableProtocols() return ChooseDefaultProtocol(availableProtocols) diff --git a/azurelinuxagent/protocol/v1.py b/azurelinuxagent/protocol/v1.py index b83fb0b..4f92922 100644 --- a/azurelinuxagent/protocol/v1.py +++ b/azurelinuxagent/protocol/v1.py @@ -823,7 +823,6 @@ class Certificates(object): shellutil.Run(cmd) #The parsing process use public key to match prv and crt. - #TODO: Is there any way better to do so? buf = [] beginCrt = False beginPrv = False diff --git a/bin/azurela b/bin/azurela deleted file mode 100755 index 98e096d..0000000 --- a/bin/azurela +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env python -# -# Windows Azure Linux Agent -# -# 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 sys -import azurelinuxagent.agent as agent -if __name__ == '__main__' : - agent.Main() - diff --git a/config/suse/waagent.conf b/config/suse/waagent.conf index 475095f..e429c74 100644 --- a/config/suse/waagent.conf +++ b/config/suse/waagent.conf @@ -66,3 +66,5 @@ OS.OpensslPath=None #HttpProxy.Host=None #HttpProxy.Port=None +# Detect Scvmm environment, default is n +# DetectScvmmEnv=n diff --git a/config/ubuntu/waagent.conf b/config/ubuntu/waagent.conf index 4acce27..ab50418 100644 --- a/config/ubuntu/waagent.conf +++ b/config/ubuntu/waagent.conf @@ -66,3 +66,5 @@ OS.OpensslPath=None #HttpProxy.Host=None #HttpProxy.Port=None +# Detect Scvmm environment, default is n +# DetectScvmmEnv=n diff --git a/config/waagent.conf b/config/waagent.conf index 756eb4d..4435d56 100644 --- a/config/waagent.conf +++ b/config/waagent.conf @@ -50,9 +50,6 @@ ResourceDisk.EnableSwap=n # Size of the swapfile. ResourceDisk.SwapSizeMB=0 -# Respond to load balancer probes if requested by Windows Azure. -LBProbeResponder=y - # Enable verbose logging (y|n) Logs.Verbose=n @@ -66,3 +63,5 @@ OS.OpensslPath=None #HttpProxy.Host=None #HttpProxy.Port=None +# Detect Scvmm environment, default is n +# DetectScvmmEnv=n diff --git a/init/waagent b/init/waagent index 9459d00..fe30d4d 100755 --- a/init/waagent +++ b/init/waagent @@ -17,6 +17,9 @@ start() { echo -n $"Starting $FriendlyName: " $WAZD_BIN -start + RETVAL=$? + echo + return $RETVAL } stop() diff --git a/setup.py b/setup.py index d24b8e1..f0753a0 100755 --- a/setup.py +++ b/setup.py @@ -38,7 +38,7 @@ def get_data_files(name, version, fullname): #Script file script_dest = '/usr/sbin' - script_src = ['bin/waagent', 'bin/azurela'] + script_src = ['bin/waagent'] if name == 'coreos': script_dest = '/usr/share/oem/bin' data_files.append((script_dest, script_src))