def test_snmp_g02(self):
		""" snmp_g02 """
		snmp = {
			"enable": True,
			"community": "public",
			"system_name": "SLB",
			"system_contact": "info <*****@*****.**>",
			"system_location": "4F, 102 Guangfu S. Road, Daan District, Taipei 10612, Taiwan"
		}
		self.maxDiff = None
		e = ml_w_snmp.set(None, snmp)
		self.assertTrue(e[0], e[1])
		f = open(os.path.join("running", "snmp.txt"), "r")
		e = f.readlines()
		f.close()
		if "json" == ml_system.CFG_TYPE:
			self.assertEqual(e, ['{"system_name": "SLB", "system_contact": "info <*****@*****.**>", "enable": true, "system_location": "4F, 102 Guangfu S. Road, Daan District, Taipei 10612, Taiwan", "community": "public"}'])
		if "jcfg" == ml_system.CFG_TYPE:
			self.assertEqual(e, ['snmp {\n', '    enable True\n', '    community public\n', '    system_name SLB\n', '    system_contact "info <*****@*****.**>"\n', '    system_location "4F, 102 Guangfu S. Road, Daan District, Taipei 10612, Taiwan"\n', '}\n'])
Example #2
0
    def snmp(self, **kwargs):
        '''
            snmp setting
            data format from middleware
            (True, {'system_name': 'SLB', 'system_contact': '', 'enable': False, 'system_loca
tion': '', 'community': 'public'})
        '''
        import libs.login
        if False == libs.login.cklogin():
            raise _.HTTPRedirect('/')

        import ml_w_snmp as snmp
        import json
        import libs.tools

        _.response.headers["Content-Type"] = "application/json"
        if 'system_name' in kwargs:
            # for updating setting
            libs.tools.v(kwargs)

            res = {'system_name': libs.tools.convert(kwargs['system_name']),
                   'system_contact': libs.tools.convert(kwargs['system_contact']),
                   'enable': 'enable' in kwargs,
                   'system_location': libs.tools.convert(kwargs['system_location']),
                   'community': libs.tools.convert(kwargs['community'])}

            libs.tools.v(res)

            res = snmp.set(user = self.getUser(), cfg = res)
            if False == res[0]:
                return json.dumps([res[0], libs.tools.translateMessage(res[1])])
            else:
                return json.dumps(res)
        else:
            # for information getter
            return json.dumps(snmp.get())
			def run(self):
				e = ml_w_snmp.set(None, snmp, threading.RLock())