Просмотр исходного кода

CTS: fix the test_agent start/stop/status mechanism.

git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@2763 fd59a12c-fef9-0310-b244-a6a79926bd2f
Angus Salkeld 16 лет назад
Родитель
Сommit
8c476ce395
4 измененных файлов с 49 добавлено и 34 удалено
  1. 3 0
      cts/agents/confdb_test_agent.c
  2. 4 2
      cts/agents/cpg_test_agent.c
  3. 4 4
      cts/agents/votequorum_test_agent.c
  4. 38 28
      cts/corosync.py

+ 3 - 0
cts/agents/confdb_test_agent.c

@@ -583,6 +583,9 @@ static void do_command (int sock, char* func, char*args[], int num_args)
 		object_find_test (sock);
 		object_find_test (sock);
 	} else if (strcmp ("notification_test", func) == 0) {
 	} else if (strcmp ("notification_test", func) == 0) {
 		notification_test (sock);
 		notification_test (sock);
+	} else if (strcmp ("are_you_ok_dude", func) == 0) {
+		snprintf (response, 100, "%s", OK_STR);
+		send (sock, response, strlen (response) + 1, 0);
 	} else {
 	} else {
 		syslog (LOG_ERR,"%s RPC:%s not supported!", __func__, func);
 		syslog (LOG_ERR,"%s RPC:%s not supported!", __func__, func);
 		snprintf (response, 100, "%s", NOT_SUPPORTED_STR);
 		snprintf (response, 100, "%s", NOT_SUPPORTED_STR);

+ 4 - 2
cts/agents/cpg_test_agent.c

@@ -487,6 +487,7 @@ static int cpg_dispatch_wrapper_fn (hdb_handle_t handle,
 static void do_command (int sock, char* func, char*args[], int num_args)
 static void do_command (int sock, char* func, char*args[], int num_args)
 {
 {
 	int result;
 	int result;
+	char response[100];
 	struct cpg_name group_name;
 	struct cpg_name group_name;
 
 
 	if (parse_debug)
 	if (parse_debug)
@@ -547,7 +548,6 @@ static void do_command (int sock, char* func, char*args[], int num_args)
 
 
 	} else if (strcmp ("cpg_local_get", func) == 0) {
 	} else if (strcmp ("cpg_local_get", func) == 0) {
 		unsigned int local_nodeid;
 		unsigned int local_nodeid;
-		char response[100];
 
 
 		cpg_local_get (cpg_handle, &local_nodeid);
 		cpg_local_get (cpg_handle, &local_nodeid);
 		snprintf (response, 100, "%u",local_nodeid);
 		snprintf (response, 100, "%u",local_nodeid);
@@ -582,7 +582,9 @@ static void do_command (int sock, char* func, char*args[], int num_args)
 	} else if (strcmp ("msg_blaster",func) == 0) {
 	} else if (strcmp ("msg_blaster",func) == 0) {
 
 
 		msg_blaster (sock, args[0]);
 		msg_blaster (sock, args[0]);
-
+	} else if (strcmp ("are_you_ok_dude", func) == 0) {
+		snprintf (response, 100, "%s", OK_STR);
+		send (sock, response, strlen (response) + 1, 0);
 	} else {
 	} else {
 		syslog (LOG_ERR,"%s RPC:%s not supported!", __func__, func);
 		syslog (LOG_ERR,"%s RPC:%s not supported!", __func__, func);
 	}
 	}

+ 4 - 4
cts/agents/votequorum_test_agent.c

@@ -163,17 +163,14 @@ static void lib_init (int sock)
 	int ret;
 	int ret;
 	char response[100];
 	char response[100];
 
 
+	snprintf (response, 100, "%s", OK_STR);
 	ret = q_lib_init ();
 	ret = q_lib_init ();
 
 
 	if (ret != CS_OK) {
 	if (ret != CS_OK) {
 		snprintf (response, 100, "%s", FAIL_STR);
 		snprintf (response, 100, "%s", FAIL_STR);
 		syslog (LOG_ERR, "q_lib_init FAILED: %d\n", ret);
 		syslog (LOG_ERR, "q_lib_init FAILED: %d\n", ret);
-		goto send_response;
 	}
 	}
 
 
-	snprintf (response, 100, "%s", OK_STR);
-
-send_response:
 	send (sock, response, strlen (response), 0);
 	send (sock, response, strlen (response), 0);
 }
 }
 
 
@@ -285,6 +282,9 @@ static void do_command (int sock, char* func, char*args[], int num_args)
 		getquorate (sock);
 		getquorate (sock);
 	} else if (strcmp ("init", func) == 0) {
 	} else if (strcmp ("init", func) == 0) {
 		lib_init (sock);
 		lib_init (sock);
+	} else if (strcmp ("are_you_ok_dude", func) == 0) {
+		snprintf (response, 100, "%s", OK_STR);
+		send (sock, response, strlen (response) + 1, 0);
 	} else {
 	} else {
 		syslog (LOG_ERR,"%s RPC:%s not supported!", __func__, func);
 		syslog (LOG_ERR,"%s RPC:%s not supported!", __func__, func);
 		snprintf (response, 100, "%s", NOT_SUPPORTED_STR);
 		snprintf (response, 100, "%s", NOT_SUPPORTED_STR);

+ 38 - 28
cts/corosync.py

@@ -220,8 +220,15 @@ class corosync_flatiron(ClusterManager):
             self.confdb_agent[node].restart()
             self.confdb_agent[node].restart()
         if self.sam_agent.has_key(node):
         if self.sam_agent.has_key(node):
             self.sam_agent[node].restart()
             self.sam_agent[node].restart()
-        if self.votequorum_agent.has_key(node):
-            self.votequorum_agent[node].restart()
+
+        # votequorum agent started as needed.
+        if self.applied_config.has_key('quorum/provider'):
+            if self.votequorum_agent.has_key(node):
+                self.votequorum_agent[node].restart()
+            else:
+                self.votequorum_agent[node] = VoteQuorumTestAgent(node, self.Env)
+                self.votequorum_agent[node].start()
+
         return ret
         return ret
 
 
     def StopaCM(self, node):
     def StopaCM(self, node):
@@ -339,8 +346,10 @@ class TestAgentComponent(ScenarioComponent):
             self.CM.confdb_agent[node].start()
             self.CM.confdb_agent[node].start()
             self.CM.sam_agent[node] = SamTestAgent(node, CM.Env)
             self.CM.sam_agent[node] = SamTestAgent(node, CM.Env)
             self.CM.sam_agent[node].start()
             self.CM.sam_agent[node].start()
-            self.CM.votequorum_agent[node] = VoteQuorumTestAgent(node, CM.Env)
-            self.CM.votequorum_agent[node].start()
+            # votequorum agent started as needed.
+            if CM.applied_config.has_key('quorum/provider'):
+                self.CM.votequorum_agent[node] = VoteQuorumTestAgent(node, CM.Env)
+                self.CM.votequorum_agent[node].start()
         return 1
         return 1
 
 
     def TearDown(self, CM):
     def TearDown(self, CM):
@@ -350,7 +359,8 @@ class TestAgentComponent(ScenarioComponent):
             self.CM.cpg_agent[node].stop()
             self.CM.cpg_agent[node].stop()
             self.CM.confdb_agent[node].stop()
             self.CM.confdb_agent[node].stop()
             self.CM.sam_agent[node].stop()
             self.CM.sam_agent[node].stop()
-            self.CM.votequorum_agent[node].stop()
+            if self.CM.votequorum_agent.has_key(node):
+                self.CM.votequorum_agent[node].stop()
 
 
 ###################################################################
 ###################################################################
 class TestAgent(object):
 class TestAgent(object):
@@ -374,7 +384,7 @@ class TestAgent(object):
 
 
     def clean_start(self):
     def clean_start(self):
         if self.used or not self.status():
         if self.used or not self.status():
-            self.env.debug('test agent: clean_start (' + self.node + ')')
+            self.env.debug('test agent: cleaning %s on node %s' % (self.binary, self.node))
             self.stop()
             self.stop()
             self.start()
             self.start()
 
 
@@ -383,15 +393,17 @@ class TestAgent(object):
             return False
             return False
 
 
         try:
         try:
-            self.send (["cpg_local_get"])  
-            self.nodeid = self.read ()
+            self.send (["are_you_ok_dude"])  
+            self.read ()
+            self.started = True
             return True
             return True
         except RuntimeError, msg:
         except RuntimeError, msg:
+            self.started = False
             return False
             return False
     
     
     def start(self):
     def start(self):
         '''Set up the given ScenarioComponent'''
         '''Set up the given ScenarioComponent'''
-        self.env.debug('test agent: start (' + self.node + ')')
+        self.env.debug('test agent: starting %s on node %s' % (self.binary, self.node))
         self.sock = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
         self.sock = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
         ip = socket.gethostbyname(self.node)
         ip = socket.gethostbyname(self.node)
         self.rsh(self.node, self.binary, blocking=0)
         self.rsh(self.node, self.binary, blocking=0)
@@ -404,17 +416,18 @@ class TestAgent(object):
                 is_connected = True
                 is_connected = True
             except socket.error, msg:
             except socket.error, msg:
                 if retries > 5:
                 if retries > 5:
-                    self.env.debug("Retried " + str(retries) + " times. Error: " + str(msg))
+                    self.env.log("Retried " + str(retries) + " times. Error: " + str(msg))
                 time.sleep(1)
                 time.sleep(1)
         self.started = True
         self.started = True
         self.used = False
         self.used = False
 
 
     def stop(self):
     def stop(self):
         '''Tear down (undo) the given ScenarioComponent'''
         '''Tear down (undo) the given ScenarioComponent'''
-        self.env.debug('test agent: stop (' + self.node + ')')
-        self.sock.close ()
-        self.rsh(self.node, "killall " + self.binary + " 2>/dev/null")
-        self.started = False
+        if self.status():
+            self.env.debug('test agent: stopping %s on node %s' % (self.binary, self.node))
+            self.sock.close ()
+            self.rsh(self.node, "killall " + self.binary + " 2>/dev/null")
+            self.started = False
 
 
     def send (self, args):
     def send (self, args):
         if not self.started:
         if not self.started:
@@ -508,13 +521,15 @@ class CpgTestAgent(TestAgent):
         self.nodeid = None
         self.nodeid = None
 
 
     def start(self):
     def start(self):
-        TestAgent.start(self)
-        self.send(["cpg_initialize"])
-        self.used = False
+        if not self.started:
+            TestAgent.start(self)
+            self.cpg_initialize()
+            self.used = False
 
 
     def stop(self):
     def stop(self):
         try:
         try:
-            self.send(["cpg_finalize"])
+            if self.started:
+                self.cpg_finalize()
         except RuntimeError, msg:
         except RuntimeError, msg:
             # if cpg_agent is down, we are not going to stress
             # if cpg_agent is down, we are not going to stress
             print msg
             print msg
@@ -560,9 +575,6 @@ class ConfdbTestAgent(TestAgent):
         self.nodeid = None
         self.nodeid = None
         self.send_recv = True
         self.send_recv = True
 
 
-    def cpg_local_get(self):
-        return 1
-
 ###################################################################
 ###################################################################
 class SamTestAgent(TestAgent):
 class SamTestAgent(TestAgent):
 
 
@@ -572,9 +584,6 @@ class SamTestAgent(TestAgent):
         self.nodeid = None
         self.nodeid = None
         self.send_recv = True
         self.send_recv = True
 
 
-    def cpg_local_get(self):
-        return 1
-
 ###################################################################
 ###################################################################
 class VoteQuorumTestAgent(TestAgent):
 class VoteQuorumTestAgent(TestAgent):
 
 
@@ -583,9 +592,10 @@ class VoteQuorumTestAgent(TestAgent):
         self.initialized = False
         self.initialized = False
         self.nodeid = None
         self.nodeid = None
         self.send_recv = True
         self.send_recv = True
-        self.send (['init'])  
-
-    def cpg_local_get(self):
-        return 1
 
 
+    def start(self):
+        if not self.started:
+            TestAgent.start(self)
+            self.init()
+            self.used = False