def _double_agents_test(self, agent, parent_agent):
     parent_name = 'celery@{0}'.format(parent_agent['name'])
     inspect = celery.control.inspect(destination=[parent_name])
     self.assertFalse(inspect.active())
     self.call('install', parent_agent)
     self.assertTrue(inspect.active())
     self.logger.info('Agent {0} active.'.format(parent_agent['name']))
     try:
         # Must end with .py:
         installer_name = 'installer.py'
         output = os.path.join(self.base_dir, installer_name)
         install_utils.prepare_script(agent,
                                      output)
         worker_name = 'celery@{0}'.format(agent['name'])
         worker_inspect = celery.control.inspect(
             destination=[worker_name])
         self.assertFalse(worker_inspect.active())
         celery_app = Celery(broker='amqp://', backend='amqp://')
         self.logger.info('Sending installer task')
         result = celery_app.send_task(
             'script_runner.tasks.run',
             args=['http://localhost:8000/{0}'.format(installer_name)],
             queue=parent_agent['queue'])
         result.get()
         self.assertTrue(worker_inspect.active())
         self.call('uninstall', agent)
         self.assertFalse(worker_inspect.active())
     finally:
         self.call('uninstall', parent_agent)
         self.assertFalse(inspect.active())
 def setUp(self):
     self.logger = setup_logger('InstallerTest')
     config_path = os.environ.get('CONFIG_PATH')
     self.logger.info('Config: {0}'.format(config_path))
     with open(config_path) as config_file:
         self.config = yaml.load(config_file)
     self.logger.info(str(self.config))
     current_ctx.set(MockCloudifyContext())
     self.runner = LocalCommandRunner(self.logger)
     self.base_dir = tempfile.mkdtemp()
     self.logger.info('Base dir: {0}'.format(self.base_dir))
     _, self.script_path = tempfile.mkstemp(dir=self.base_dir,
                                            suffix='.py')
     install_utils.prepare_script({}, self.script_path)