1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
13 import vstf.controller.settings.settings as sets
14 import vstf.common.decorator as deco
15 from vstf.common.input import raw_choice
17 LOG = logging.getLogger(__name__)
20 class MailSettings(sets.Settings):
21 def __init__(self, path="/etc/vstf", filename="reporters.mail.mail-settings", mode=sets.SETS_DEFAULT):
22 super(MailSettings, self).__init__(path, filename, mode)
24 def _register_func(self):
25 super(MailSettings, self)._register_func()
27 self._fset['body'].keys()
32 func_name = "set_%s" % item
33 setattr(self, func_name, self._setting_file(func_name, self._mset['body'], self._fset['body'], item))
34 other = {"attach", "content", "subtype"}
36 func_name = "mset_%s" % item
37 setattr(self, func_name, self._setting_memory(func_name, self._mset['body'], item))
39 LOG.debug(self.__dict__)
42 if raw_choice("if set mail server"):
43 server = self.raw_server()
44 self.set_server(server)
46 if raw_choice("if set mail body"):
47 body = self.raw_body()
49 print "%s set finish: " % (self._filename)
50 print "+++++++++++++++++++++++++++++++++++++++++"
51 pprint.pprint(self.settings, indent=4)
52 print "+++++++++++++++++++++++++++++++++++++++++"
54 @deco.vstf_input("password", types=str)
55 @deco.vstf_input("username", types=str)
56 @deco.vstf_input('host', types=str)
58 print "---------------------------------------"
59 print "Please vstf set mail server info like:"
60 print " 'host': 'localhost',"
61 print " 'username': 'user',['\\n' = None]"
62 print " 'password': '******',['\\n' = None]"
63 print "---------------------------------------"
65 @deco.vstf_input("subject", types=str, default='vstf mail')
66 @deco.vstf_input("bcc", types=list, default=[])
67 @deco.vstf_input("cc", types=list, default=[])
68 @deco.vstf_input("to", types=list, default=[])
69 @deco.vstf_input('from', types=list, default=['vstf_from@vstf.com'])
71 print "----------------------------------------------------"
72 print "Please vstf set mail server info like:"
73 print " 'from': ['vstf_from@vstf.com'],"
74 print " 'to': ['vstf_to@vstf.com'],"
75 print " 'cc': ['vstf_cc@vstf.com']"
76 print " 'bcc': ['vstf_bcc@vstf.com']"
77 print " 'subject': Vstf Performance Test Report"
78 print "----------------------------------------------------"
82 from vstf.common.log import setup_logging
83 setup_logging(level=logging.DEBUG, log_file="/var/log/vstf/vstf-mail-settings.log", clevel=logging.INFO)
85 mail_settings = MailSettings()
86 mail_settings.sinput()
95 mail_settings.set_server(mail_server)
97 subject = "Virtual Switching Performance Test Report"
98 mail_settings.set_subject(subject)
101 mail_settings.mset_subtype(subtype)
104 mail_settings.mset_attach(attach_list)
106 content = "this is a test"
107 mail_settings.mset_content(content)
109 LOG.info(mail_settings.settings)
112 if __name__ == '__main__':