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):
25 filename="reporters.mail.mail-settings",
26 mode=sets.SETS_DEFAULT):
27 super(MailSettings, self).__init__(path, filename, mode)
29 def _register_func(self):
30 super(MailSettings, self)._register_func()
32 self._fset['body'].keys()
37 func_name = "set_%s" % item
46 other = {"attach", "content", "subtype"}
48 func_name = "mset_%s" % item
57 LOG.debug(self.__dict__)
60 if raw_choice("if set mail server"):
61 server = self.raw_server()
62 self.set_server(server)
64 if raw_choice("if set mail body"):
65 body = self.raw_body()
67 print "%s set finish: " % (self._filename)
68 print "+++++++++++++++++++++++++++++++++++++++++"
69 pprint.pprint(self.settings, indent=4)
70 print "+++++++++++++++++++++++++++++++++++++++++"
72 @deco.vstf_input("password", types=str)
73 @deco.vstf_input("username", types=str)
74 @deco.vstf_input('host', types=str)
76 print "---------------------------------------"
77 print "Please vstf set mail server info like:"
78 print " 'host': 'localhost',"
79 print " 'username': 'user',['\\n' = None]"
80 print " 'password': '******',['\\n' = None]"
81 print "---------------------------------------"
83 @deco.vstf_input("subject", types=str, default='vstf mail')
84 @deco.vstf_input("bcc", types=list, default=[])
85 @deco.vstf_input("cc", types=list, default=[])
86 @deco.vstf_input("to", types=list, default=[])
87 @deco.vstf_input('from', types=list, default=['vstf_from@vstf.com'])
89 print "----------------------------------------------------"
90 print "Please vstf set mail server info like:"
91 print " 'from': ['vstf_from@vstf.com'],"
92 print " 'to': ['vstf_to@vstf.com'],"
93 print " 'cc': ['vstf_cc@vstf.com']"
94 print " 'bcc': ['vstf_bcc@vstf.com']"
95 print " 'subject': Vstf Performance Test Report"
96 print "----------------------------------------------------"
100 from vstf.common.log import setup_logging
103 log_file="/var/log/vstf/vstf-mail-settings.log",
106 mail_settings = MailSettings()
107 mail_settings.sinput()
116 mail_settings.set_server(mail_server)
118 subject = "Virtual Switching Performance Test Report"
119 mail_settings.set_subject(subject)
122 mail_settings.mset_subtype(subtype)
125 mail_settings.mset_attach(attach_list)
127 content = "this is a test"
128 mail_settings.mset_content(content)
130 LOG.info(mail_settings.settings)
133 if __name__ == '__main__':