def test_add_service_duplicated(self): self.newSetUp() service_cnt = len(self.services) #duplicated entry check: the matching service was in the same transaction self.start_transaction() self.send_message(messages.KZorpAddProxyServiceMessage("dupe1")) res = self.send_message(messages.KZorpAddProxyServiceMessage("dupe1"), assert_on_error=False) self.end_transaction() self.assertEqual(-errno.EEXIST, res) service_cnt += 1 self.check_svc_num(service_cnt) #duplicated entry check: the matching service was already existing self.check_send(messages.KZorpAddProxyServiceMessage("dupe1"), -errno.EEXIST) self.check_svc_num(service_cnt)
def test_add_service_flags(self): self.newSetUp() service_cnt = len(self.services) for i in range(2 * messages.KZF_SVC_LOGGING): self.check_send(messages.KZorpAddProxyServiceMessage("flag-%d" % i, i), 0) service_cnt += 2 * messages.KZF_SVC_LOGGING self.check_svc_num(service_cnt) # using undefined flags self.start_transaction() res = self.send_message(messages.KZorpAddProxyServiceMessage("flag-invalid", flags=0xfffffffc), assert_on_error=False) self.end_transaction() self.assertNotEqual(0, res)
def setup_service_dispatcher(self, services, dispatchers, add_zone = True, add_service = True): self._dumped_diszpancsers = [] self.start_transaction() if add_zone: self._addzones() if add_service: for service in services: if type(service) == types.DictType: service = service['name'] self.send_message(messages.KZorpAddProxyServiceMessage(service)) for dispatcher in dispatchers: message_add_dispatcher = messages.KZorpAddDispatcherMessage(dispatcher['name'], dispatcher['num_rules'] ) self.send_message(message_add_dispatcher, error_handler=lambda res: os.strerror(res)+" "+str(message_add_dispatcher)) for rule in dispatcher['rules']: _max = 0 for name, value in rule['entry_nums'].items(): if _max < value: _max = value message_add_rule = messages.KZorpAddRuleMessage(dispatcher['name'], rule['rule_id'], rule['service'], rule['entry_nums'] ) self.send_message(message_add_rule) for i in range(_max): data = {} for dim_type in messages.N_DIMENSION_ATTRS: if dim_type in rule['entry_nums'] and rule['entry_nums'][dim_type] > i: if dim_type in [messages.KZNL_ATTR_N_DIMENSION_SRC_IP, messages.KZNL_ATTR_N_DIMENSION_DST_IP]: subnet = rule['entry_values'][dim_type][i] data[dim_type] = (testutil.addr_packed(subnet), testutil.netmask_packed(subnet)) elif dim_type in [messages.KZNL_ATTR_N_DIMENSION_SRC_IP6, messages.KZNL_ATTR_N_DIMENSION_DST_IP6]: subnet = rule['entry_values'][dim_type][i] data[dim_type] = (testutil.addr_packed6(subnet), testutil.netmask_packed6(subnet)) else: data[dim_type] = rule['entry_values'][dim_type][i] #print "rule=%s\ndispatcher=%s\ndata=%s\n"%(rule,dispatcher['name'],data) message_add_rule_entry = messages.KZorpAddRuleEntryMessage(dispatcher['name'], rule['rule_id'], data) self.send_message(message_add_rule_entry) self.end_transaction()