Ejemplo n.º 1
0
def main():
    #Global Variables definition
    waagent.LoggerInit('/var/log/waagent.log', '/dev/stdout')
    waagent.Log("%s started to handle." % (ExtensionShortName))

    operation = "disable"
    status = "success"
    msg = "Disabled successfully."

    hutil = parse_context(operation)
    hutil.log("Start to disable.")
    hutil.log(msg)
    hutil.do_exit(0, operation, status, '0', msg)
Ejemplo n.º 2
0
def main():
    waagent.LoggerInit('/var/log/waagent.log', '/dev/stdout')
    waagent.Log("%s started to handle." % (ExtensionShortName))

    for a in sys.argv[1:]:
        if re.match("^([-/]*)(disable)", a):
            disable()
        elif re.match("^([-/]*)(uninstall)", a):
            uninstall()
        elif re.match("^([-/]*)(install)", a):
            install()
        elif re.match("^([-/]*)(enable)", a):
            enable()
        elif re.match("^([-/]*)(update)", a):
            update()
def init_globals():
    """Initialize all the globals in a function so that we can catch any exceptions that might be raised."""
    global hutil, g_ext_dir, g_mdsd_file_resources_prefix, g_lad_pids_filepath
    global g_diagnostic_py_filepath, g_lad_log_helper

    waagent.LoggerInit('/var/log/waagent.log', '/dev/stdout')
    waagent.Log("LinuxDiagnostic started to handle.")
    hutil = Util.HandlerUtility(waagent.Log, waagent.Error)
    init_extension_settings()
    init_distro_specific_actions()

    g_ext_dir = os.getcwd()
    g_mdsd_file_resources_prefix = os.path.join(g_mdsd_file_resources_dir, g_mdsd_role_name)
    g_lad_pids_filepath = os.path.join(g_ext_dir, 'lad.pids')
    g_diagnostic_py_filepath = os.path.join(os.getcwd(), __file__)
    g_lad_log_helper = LadLogHelper(hutil.log, hutil.error, waagent.AddExtensionEvent, hutil.do_status_report,
                                    hutil.get_name(), hutil.get_extension_version())
Ejemplo n.º 4
0
def main():
    #Global Variables definition
    waagent.LoggerInit('/var/log/waagent.log', '/dev/stdout')
    waagent.Log("%s started to handle." % (ExtensionShortName))

    operation = "enable"
    status = "success"
    msg = "Enabled successfully."

    hutil = parse_context(operation)
    hutil.log("Start to enable.")
    public_settings = hutil.get_public_settings()
    name = public_settings.get("name")
    if name:
        hutil.log("Hello {0}".format(name))
    else:
        hutil.error("The name in public settings is not provided.")
    hutil.log(msg)
    hutil.do_exit(0, operation, status, '0', msg)
Ejemplo n.º 5
0
def main():
    waagent.LoggerInit('/var/log/waagent.log', '/dev/stdout')
    waagent.Log("%s started to handle." % (ExtensionShortName))

    try:
        for a in sys.argv[1:]:
            if re.match("^([-/]*)(disable)", a):
                disable()
            elif re.match("^([-/]*)(uninstall)", a):
                uninstall()
            elif re.match("^([-/]*)(install)", a):
                install()
            elif re.match("^([-/]*)(enable)", a):
                enable()
            elif re.match("^([-/]*)(update)", a):
                update()
    except Exception as e:
        err_msg = "Failed with error: {0}, {1}".format(e, traceback.format_exc())
        waagent.Error(err_msg)
Ejemplo n.º 6
0
def main():
    waagent.LoggerInit('/var/log/waagent.log', '/dev/stdout')
    waagent.Log("%s started to handle." % (ExtensionShortName))

    global hutil
    hutil = Util.HandlerUtility(waagent.Log, waagent.Error)
    hutil.try_parse_context()

    global public_settings
    public_settings = hutil.get_public_settings()
    if not public_settings:
        waagent.AddExtensionEvent(name=ExtensionShortName,
                                  op='MainInProgress',
                                  isSuccess=True,
                                  message="Public settings are NOT provided.")
        public_settings = {}

    global protected_settings
    protected_settings = hutil.get_protected_settings()
    if not protected_settings:
        waagent.AddExtensionEvent(
            name=ExtensionShortName,
            op='MainInProgress',
            isSuccess=True,
            message="protected settings are NOT provided.")
        protected_settings = {}

    global distro_category
    distro_category = get_distro_category()

    for a in sys.argv[1:]:
        if re.match("^([-/]*)(disable)", a):
            disable()
        elif re.match("^([-/]*)(uninstall)", a):
            uninstall()
        elif re.match("^([-/]*)(install)", a):
            install()
        elif re.match("^([-/]*)(enable)", a):
            enable()
        elif re.match("^([-/]*)(update)", a):
            update()
Ejemplo n.º 7
0
def main():
    waagent.LoggerInit('/var/log/waagent.log','/dev/stdout')
    waagent.Log("%s started to handle." %(ExtensionShortName))
    waagent.MyDistro = waagent.GetMyDistro()
    global DistroName, DistroVersion
    distro = platform.dist()
    DistroName = distro[0].lower()
    DistroVersion = distro[1]
    for a in sys.argv[1:]:        
        if re.match("^([-/]*)(disable)", a):
            disable()
        elif re.match("^([-/]*)(uninstall)", a):
            uninstall()
        elif re.match("^([-/]*)(install)", a):
            install()
        elif re.match("^([-/]*)(enable)", a):
            enable()
        elif re.match("^([-/]*)(daemon)", a):
            daemon()            
        elif re.match("^([-/]*)(update)", a):
            update()
Ejemplo n.º 8
0
    def setUp(self):
        print '\n\n============================================================================================'
        waagent.LoggerInit('/var/log/waagent.log', '/dev/stdout')
        waagent.Log("%s started to handle." % (ExtensionShortName))

        global protect_settings
        protect_settings = json.loads(contents)
        global hutil
        hutil = Util.HandlerUtility(waagent.Log, waagent.Error,
                                    ExtensionShortName)
        global MyPatching
        MyPatching = FakePatching(hutil)
        if MyPatching == None:
            sys.exit(1)

        try:
            os.remove('mrseq')
        except:
            pass

        waagent.SetFileContents(MyPatching.package_downloaded_path, '')
        waagent.SetFileContents(MyPatching.package_patched_path, '')
Ejemplo n.º 9
0
def main():
    waagent.LoggerInit('/var/log/waagent.log','/dev/stdout')
    waagent.Log("{0} started to handle.".format(ExtensionShortName))
    
    hutil = parse_context("Install")
    try:
        root = os.path.dirname(os.path.abspath(__file__))
        buildDir = os.path.join(root, "libpsutil")
        build = find_psutil_build(buildDir) 
        for item in os.listdir(build):
            src = os.path.join(build, item)
            dest = os.path.join(root, item)
            if os.path.isfile(src):
                if os.path.isfile(dest):
                    os.remove(dest)
                shutil.copyfile(src, dest)
            else:
                if os.path.isdir(dest):
                    shutil.rmtree(dest)
                shutil.copytree(src, dest)
    except Exception as e:
        hutil.error("{0}, {1}").format(e, traceback.format_exc())
        hutil.do_exit(1, "Install", 'failed','0', 
                      'Install failed: {0}'.format(e))
Ejemplo n.º 10
0
def main():
    waagent.LoggerInit('/var/log/waagent.log', '/dev/stdout')
    waagent.Log("%s started to handle." % (ExtensionShortName))

    global hutil
    hutil = Util.HandlerUtility(waagent.Log, waagent.Error, ExtensionShortName)
    global myProvision
    myProvision = GetMyProvision(hutil)
    if myProvision == None:
        sys.exit(1)

    for a in sys.argv[1:]:
        if re.match("^([-/]*)(disable)", a):
            disable()
        elif re.match("^([-/]*)(uninstall)", a):
            uninstall()
        elif re.match("^([-/]*)(install)", a):
            install()
        elif re.match("^([-/]*)(enable)", a):
            enable()
        elif re.match("^([-/]*)(update)", a):
            update()
        elif re.match("^([-/]*)(provision)", a):
            provision()
Ejemplo n.º 11
0
    def setUp(self):
        print '\n\n============================================================================================'
        waagent.LoggerInit('/var/log/waagent.log', '/dev/stdout')
        waagent.Log("%s started to handle." % (ExtensionShortName))
        global hutil
        hutil = Util.HandlerUtility(waagent.Log, waagent.Error)
        hutil.do_parse_context('TEST')

        global MyPatching
        MyPatching = FakePatching(hutil)
        if MyPatching is None:
            sys.exit(1)

        distro = DistInfo()[0]
        if 'centos' in distro or 'Oracle' in distro or 'redhat' in distro:
            MyPatching.cron_restart_cmd = 'service crond restart'

        try:
            os.remove('mrseq')
        except:
            pass

        waagent.SetFileContents(MyPatching.package_downloaded_path, '')
        waagent.SetFileContents(MyPatching.package_patched_path, '')
 def _change_log_file(self):
     self.log("Change log file to " + self._context._log_file)
     waagent.LoggerInit(self._context._log_file, '/dev/stdout')
     self._log = waagent.Log
     self._error = waagent.Error
Ejemplo n.º 13
0
import Utils.HandlerUtil as Util
import commands
import base64
import xml.dom.minidom
import xml.etree.ElementTree as ET
from collections import defaultdict
import Utils.LadDiagnosticUtil as LadUtil
import Utils.XmlUtil as XmlUtil
import Utils.ApplicationInsightsUtil as AIUtil

ExtensionShortName = 'LinuxAzureDiagnostic'
WorkDir = os.getcwd()
MDSDPidFile = os.path.join(WorkDir, 'mdsd.pid')
OutputSize = 1024
EnableSyslog = True
waagent.LoggerInit('/var/log/waagent.log','/dev/stdout')
waagent.Log("%s started to handle." %(ExtensionShortName))
hutil = Util.HandlerUtility(waagent.Log, waagent.Error, ExtensionShortName)
hutil.try_parse_context()
public_settings = hutil.get_public_settings()
private_settings = hutil.get_protected_settings()
if not public_settings:
    public_settings = {}
if not private_settings:
    private_settings = {}


def LogRunGetOutPut(cmd):
    hutil.log("RunCmd "+cmd)
    error, msg = waagent.RunGetOutput(cmd)
    hutil.log("Return "+str(error)+":"+msg)
Ejemplo n.º 14
0
#     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.

import unittest
import env
import dsc
import os
from Utils.WAAgentUtil import waagent
from MockUtil import MockUtil

waagent.LoggerInit('/tmp/test.log','/dev/null')

class TestRegister(unittest.TestCase):
    def test_register_without_registration_info(self):
        print "Register test case with invalid Registration url and Registration key"
        dsc.distro_category = dsc.get_distro_category()
        dsc.hutil = MockUtil(self)
        dsc.install_dsc_packages()
        dsc.start_omiservice()
        exit_code, output = dsc.register_automation('','','','','','')
        self.assertEqual(exit_code, 51)
		
    def test_register_invalid_configuration_mode(self):
        print "Register test case with invalid configuration mode"
        dsc.distro_category = dsc.get_distro_category()
        dsc.hutil = MockUtil(self)
# 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.6+
#

import unittest
import env
import vmaccess
import os
from Utils.WAAgentUtil import waagent
import Utils.HandlerUtil as Util

waagent.LoggerInit('/tmp/test.log', '/dev/stdout')
waagent.MyDistro = waagent.GetMyDistro()


class Dummy(object):
    pass


hutil = Dummy()
hutil.log = waagent.Log


class TestCreateNewAccount(unittest.TestCase):
    def test_creat_newuser(self):
        settings = {}
        settings['username'] = '******'
Ejemplo n.º 16
0
 def setUp(self):
     waagent.LoggerInit("/dev/null", "/dev/stdout")
         output) = self._distro.log_run_with_timeout("echo success; exit 2",
                                                     timeout=5)
        self.assertEqual(output, 'success\n')
        self.assertEqual(status, 2)

    def test_log_run_multiple_cmds(self):
        expected = 'foo\nbar\n'
        cmds = ('echo foo', 'echo bar')
        error, output = self._distro.log_run_multiple_cmds(cmds, False)
        self.assertEqual(error, 0)
        self.assertEqual(output, expected)

    def test_log_run_multiple_cmds_no_timeout(self):
        expected = 'foo\nbar\n'
        cmds = ('echo foo', 'echo bar')
        error, output = self._distro.log_run_multiple_cmds(cmds, True)
        self.assertEqual(error, 0)
        self.assertEqual(output, expected)

    def test_log_run_multiple_cmds_partial_timeout(self):
        expected = 'Process timeout\nbar\n'
        cmds = ('sleep 30; echo foo', 'echo bar')
        error, output = self._distro.log_run_multiple_cmds(cmds, True, 5)
        self.assertEqual(error, 1)
        self.assertEqual(output, expected)


if __name__ == '__main__':
    waagent.LoggerInit('waagent.verbose.log', None, True)
    unittest.main()