-# Copyright (c) 2016-2018 Intel Corporation
+# Copyright (c) 2016-2019 Intel Corporation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
             # by other VNF output
             self.q_in.put('\r\n')
 
+    def wait_for_initialize(self):
+        buf = []
+        vnf_prompt_found = False
+        prompt_command = '\r\n'
+        script_name = 'non_existent_script_name'
+        done_string = 'Cannot open file "{}"'.format(script_name)
+        time.sleep(self.WAIT_TIME)  # Give some time for config to load
+        while True:
+            if not self._vnf_process.is_alive():
+                raise RuntimeError("%s VNF process died." % self.APP_NAME)
+            while self.q_out.qsize() > 0:
+                buf.append(self.q_out.get())
+                message = ''.join(buf)
+
+                if self.VNF_PROMPT in message and not vnf_prompt_found:
+                    # Once we got VNF promt, it doesn't mean that the VNF is
+                    # up and running/initialized completely. But we can run
+                    # addition (any) VNF command and wait for it to complete
+                    # as it will be finished ONLY at the end of the VNF
+                    # initialization. So, this approach can be used to
+                    # indentify that VNF is completely initialized.
+                    LOG.info("Got %s VNF prompt.", self.APP_NAME)
+                    prompt_command = "run {}\r\n".format(script_name)
+                    self.q_in.put(prompt_command)
+                    # Cut the buffer since we are not interesting to find
+                    # the VNF prompt anymore
+                    prompt_pos = message.find(self.VNF_PROMPT)
+                    buf = [message[prompt_pos + len(self.VNF_PROMPT):]]
+                    vnf_prompt_found = True
+                    continue
+
+                if done_string in message:
+                    LOG.info("%s VNF is up and running.", self.APP_NAME)
+                    self._vnf_up_post()
+                    self.queue_wrapper.clear()
+                    return self._vnf_process.exitcode
+
+                if "PANIC" in message:
+                    raise RuntimeError("Error starting %s VNF." %
+                                       self.APP_NAME)
+
+            LOG.info("Waiting for %s VNF to start.. ", self.APP_NAME)
+            time.sleep(self.WAIT_TIME_FOR_SCRIPT)
+            # Send command again to display the expected prompt in case the
+            # expected text was corrupted by other VNF output
+            self.q_in.put(prompt_command)
+
     def start_collect(self):
         self.resource_helper.start_collect()
 
 
 
 import unittest
 import mock
+import time
 
 import paramiko
 
 
         self.assertEqual(sample_vnf.wait_for_instantiate(), 0)
 
+    @mock.patch.object(time, 'sleep')
+    @mock.patch.object(ssh, 'SSH')
+    def test_wait_for_initialize(self, ssh, *args):
+        test_base.mock_ssh(ssh, exec_result=(1, "", ""))
+        queue_get_list = [
+            'some output',
+            'pipeline> ',
+            'run non_existent_script_name',
+            'Cannot open file "non_existent_script_name"'
+        ]
+        queue_size_list = [
+            0,
+            len(queue_get_list[0]),
+            0,
+            len(queue_get_list[1]),
+            len(queue_get_list[2]),
+            0,
+            len(queue_get_list[3])
+        ]
+        vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
+        sample_vnf = SampleVNF('vnf1', vnfd)
+        sample_vnf.APP_NAME = 'sample1'
+        sample_vnf.WAIT_TIME_FOR_SCRIPT = 0
+        sample_vnf._vnf_process = mock.Mock()
+        sample_vnf._vnf_process.exitcode = 0
+        sample_vnf._vnf_process._is_alive.return_value = 1
+        sample_vnf.queue_wrapper = mock.Mock()
+        sample_vnf.q_in = mock.Mock()
+        sample_vnf.q_out = mock.Mock()
+        sample_vnf.q_out.qsize.side_effect = iter(queue_size_list)
+        sample_vnf.q_out.get.side_effect = iter(queue_get_list)
+        sample_vnf.wait_for_initialize()
+
     @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
     def test_vnf_execute_with_queue_data(self, *args):
         queue_size_list = [