def _quality_control(self, args, **extra_args):
        """
        Export is the entry point for exporting docker images.
        """
        if not isinstance(args, argparse.Namespace):
            raise Exception("args should of an instance of argparse.Namespace")

        # create new freight forwarder object
        # config_override=manifest_override
        freight_forwarder = FreightForwarder()

        # create commercial invoice this is the contact given to freight forwarder dispatch containers and images
        commercial_invoice = freight_forwarder.commercial_invoice(
            'quality_control',
            args.data_center,
            args.environment,
            args.service
        )

        # call quality control with commercial invoice and additional arguments
        bill_of_lading = freight_forwarder.quality_control(
            commercial_invoice,
            attach=args.attach,
            clean=args.clean,
            test=args.test,
            configs=args.configs,
            use_cache=args.use_cache,
            env=args.env
        )

        # pretty lame... Need to work on return values through to app to make them consistent.
        exit_code = 0 if bill_of_lading else 1

        if exit_code != 0:
            exit(exit_code)
Example #2
0
    def _test(self, args, **extra_args):
        """
        Export is the entry point for exporting docker images.
        """
        if not isinstance(args, argparse.Namespace):
            raise Exception("args should of an instance of argparse.Namespace")

        # create new freight forwarder object
        # config_override=manifest_override
        freight_forwarder = FreightForwarder()

        # create commercial invoice this is the contact given to freight forwarder dispatch containers and images
        commercial_invoice = freight_forwarder.commercial_invoice(
            'test',
            args.data_center,
            args.environment,
            args.service
        )

        # run test container.
        bill_of_lading = freight_forwarder.test(commercial_invoice, args.configs)

        # pretty lame... Need to work on return values through to app to make them consistent.
        exit_code = 0 if bill_of_lading else 1

        if exit_code != 0:
            exit(exit_code)
    def _quality_control(self, args, **extra_args):
        """
        Export is the entry point for exporting docker images.
        """
        if not isinstance(args, argparse.Namespace):
            raise Exception("args should of an instance of argparse.Namespace")

        # create new freight forwarder object
        # config_override=manifest_override
        freight_forwarder = FreightForwarder()

        # create commercial invoice this is the contact given to freight forwarder dispatch containers and images
        commercial_invoice = freight_forwarder.commercial_invoice(
            'quality_control', args.data_center, args.environment,
            args.service)

        # call quality control with commercial invoice and additional arguments
        bill_of_lading = freight_forwarder.quality_control(
            commercial_invoice,
            attach=args.attach,
            clean=args.clean,
            test=args.test,
            configs=args.configs,
            use_cache=args.use_cache,
            env=args.env)

        # pretty lame... Need to work on return values through to app to make them consistent.
        exit_code = 0 if bill_of_lading else 1

        if exit_code != 0:
            exit(exit_code)
Example #4
0
    def deploy(self, args, **extra_args):
        """Deploy a docker container to a specific container ship (host)

        :param args:
        :type args:
        """
        if not isinstance(args, argparse.Namespace):
            raise TypeError(logger.error("args should of an instance of argparse.Namespace"))

        # create new freight forwarder
        freight_forwarder = FreightForwarder()

        # create commercial invoice this is the contact given to freight forwarder to dispatch containers and images
        commercial_invoice = freight_forwarder.commercial_invoice(
            'deploy',
            args.data_center,
            args.environment,
            args.service
        )

        # deploy containers.
        bill_of_lading = freight_forwarder.deploy_containers(commercial_invoice, args.tag, args.env)

        # pretty lame... Need to work on return values through to app to make them consistent.
        exit_code = 0 if bill_of_lading else 1

        if exit_code != 0:
            exit(exit_code)
Example #5
0
    def deploy(self, args, **extra_args):
        """Deploy a docker container to a specific container ship (host)

        :param args:
        :type args:
        """
        if not isinstance(args, argparse.Namespace):
            raise TypeError(
                logger.error(
                    "args should of an instance of argparse.Namespace"))

        # create new freight forwarder
        freight_forwarder = FreightForwarder()

        # create commercial invoice this is the contact given to freight forwarder to dispatch containers and images
        commercial_invoice = freight_forwarder.commercial_invoice(
            'deploy', args.data_center, args.environment, args.service)

        # deploy containers.
        bill_of_lading = freight_forwarder.deploy_containers(
            commercial_invoice, args.tag, args.env)

        # pretty lame... Need to work on return values through to app to make them consistent.
        exit_code = 0 if bill_of_lading else 1

        if exit_code != 0:
            exit(exit_code)
 def setUp(self):
     self.freight_forwarder = FreightForwarder(
         config_path_override=os.path.join(os.getcwd(),
                                           'tests',
                                           'fixtures',
                                           'test_freight_forwarder.yaml'),
         verbose=False
     )
Example #7
0
    def _export(self, args, **extra_args):
        """
        Export is the entry point for exporting docker images.
        """
        if not isinstance(args, argparse.Namespace):
            raise TypeError(
                logger.error(
                    "args should of an instance of argparse.Namespace"))

        # Warn the consumer about unsafe Docker Practices
        if args.no_validation:
            logger.warning(
                "#######################################################\n"
                "Validation has been disabled for this export operation.\n"
                "This is an unsafe operation and does not verify the "
                "run time nature of the container.\n"
                "Any docker image created in this manner will not "
                "be verified to start. Do not ship broken code.\n"
                "#######################################################\n",
                extra={'formatter': 'cli-warning'})

            # Require the consumer to verify their actions
            if not args.y:
                validation_input = six.moves.input(
                    "Please type \'yes\' to export the container without validation: "
                )

                if not (isinstance(validation_input, six.string_types) and
                        ('yes' == validation_input)):
                    raise ValueError(
                        "Incorrect type defined. Required value: yes")

        # create new freight forwarder to create a commercial_invoice and export goods.
        freight_forwarder = FreightForwarder()

        # create commercial invoice this is the contact given to freight forwarder dispatch containers and images
        commercial_invoice = freight_forwarder.commercial_invoice(
            'export',
            args.data_center,
            args.environment,
            args.service,
            tagging_scheme=not args.no_tagging_scheme)

        # create commercial_invoice
        bill_of_lading = freight_forwarder.export(
            commercial_invoice,
            clean=args.clean,
            configs=args.configs,
            tags=args.tag,
            test=args.test,
            use_cache=args.use_cache,
            validate=not args.no_validation)

        # pretty lame... Need to work on return values through to app to make them consistent.
        exit_code = 0 if bill_of_lading else 1

        if exit_code != 0:
            exit(exit_code)
Example #8
0
    def _export(self, args, **extra_args):
        """
        Export is the entry point for exporting docker images.
        """
        if not isinstance(args, argparse.Namespace):
            raise TypeError(logger.error("args should of an instance of argparse.Namespace"))

        # Warn the consumer about unsafe Docker Practices
        if args.no_validation:
            logger.warning("#######################################################\n"
                           "Validation has been disabled for this export operation.\n"
                           "This is an unsafe operation and does not verify the "
                           "run time nature of the container.\n"
                           "Any docker image created in this manner will not "
                           "be verified to start. Do not ship broken code.\n"
                           "#######################################################\n",
                           extra={'formatter': 'cli-warning'})

            # Require the consumer to verify their actions
            if not args.y:
                validation_input = six.moves.input("Please type \'yes\' to export the container without validation: ")

                if not (isinstance(validation_input, six.string_types) and ('yes' == validation_input)):
                    raise ValueError("Incorrect type defined. Required value: yes")

        # create new freight forwarder to create a commercial_invoice and export goods.
        freight_forwarder = FreightForwarder()

        # create commercial invoice this is the contact given to freight forwarder dispatch containers and images
        commercial_invoice = freight_forwarder.commercial_invoice(
            'export',
            args.data_center,
            args.environment,
            args.service,
            tagging_scheme=not args.no_tagging_scheme
        )

        # create commercial_invoice
        bill_of_lading = freight_forwarder.export(
            commercial_invoice,
            attach=args.attach,
            clean=args.clean,
            configs=args.configs,
            tags=args.tag,
            test=args.test,
            use_cache=args.use_cache,
            validate=not args.no_validation
        )

        # pretty lame... Need to work on return values through to app to make them consistent.
        exit_code = 0 if bill_of_lading else 1

        if exit_code != 0:
            exit(exit_code)
class FreightForwarderTest(unittest.TestCase):
    def setUp(self):
        self.freight_forwarder = FreightForwarder(
            config_path_override=os.path.join(os.getcwd(),
                                              'tests',
                                              'fixtures',
                                              'test_freight_forwarder.yaml'),
            verbose=False
        )

    def tearDown(self):
        del self.freight_forwarder

    @mock.patch('freight_forwarder.freight_forwarder.CommercialInvoice', create=True)
    def test_commercial_invoice_export_and_deploy_service(self, mock_commercial_invoice):
        commercial_invoice = self.freight_forwarder.commercial_invoice(
            action='export',
            data_center='local',
            environment='development',
            transport_service='tomcat-test'
        )
        commercial_invoice_services = mock_commercial_invoice.call_args[1].get('services')
        self.assertEqual(commercial_invoice_services['tomcat_test']['build'],
                          './Dockerfile')
        self.assertIsInstance(commercial_invoice_services['tomcat_test'], ConfigDict)

        self.assertNotIn('image', commercial_invoice_services['tomcat_test'].values())
class FreightForwarderTest(unittest.TestCase):
    def setUp(self):
        self.freight_forwarder = FreightForwarder(
            config_path_override=os.path.join(os.getcwd(),
                                              'tests',
                                              'fixtures',
                                              'test_freight_forwarder.yaml'),
            verbose=False
        )

    def tearDown(self):
        del self.freight_forwarder

    @mock.patch('freight_forwarder.freight_forwarder.CommercialInvoice', create=True)
    def test_commercial_invoice_export_and_deploy_service(self, mock_commercial_invoice):
        self.freight_forwarder.commercial_invoice(
            action='export',
            data_center='local',
            environment='development',
            transport_service='tomcat-test'
        )
        commercial_invoice_services = mock_commercial_invoice.call_args[1].get('services')
        self.assertEqual(commercial_invoice_services['tomcat_test']['build'],
                         './Dockerfile')
        self.assertIsInstance(commercial_invoice_services['tomcat_test'], ConfigDict)

        self.assertNotIn('image', commercial_invoice_services['tomcat_test'].values())

    @mock.patch.object(FreightForwarder, '_FreightForwarder__complete_distribution')
    @mock.patch.object(FreightForwarder, '_FreightForwarder__dispatch')
    @mock.patch.object(FreightForwarder, '_FreightForwarder__wait_for_dispatch')
    @mock.patch.object(FreightForwarder, '_FreightForwarder__service_deployment_validation')
    @mock.patch.object(FreightForwarder, '_FreightForwarder__write_state_file', autospec=True)
    @mock.patch.object(FreightForwarder, '_FreightForwarder__validate_commercial_invoice')
    @mock.patch('freight_forwarder.commercial_invoice.commercial_invoice.ContainerShip', create=True)
    @mock.patch('freight_forwarder.freight_forwarder.logger', autospec=True)
    def test_assemble_fleet_with_yaml_variables_in_hosts(self,
                                                         mock_logger,
                                                         mock_container_ship,
                                                         mock_validate_commercial_invoice,
                                                         mock_write_state_file,
                                                         mock_service_deployment_validation,
                                                         mock_wait_for_dispatch,
                                                         mock_dispatch,
                                                         mock_complete_distribution
                                                         ):
        """
        Verify that feel is built correctly based on the provided configuration data
        :param mock_commercial_invoice:
        :return:
        """
        mock_registries = mock.patch.object(CommercialInvoice, '_create_registries', return_value={
            'tune_dev': RegistryV1Factory(),
            u'docker_hub': RegistryV1Factory()
        })
        mock_registries.start()
        mock_transport_service = mock.MagicMock(return_value='tomcat-test')

        self.freight_forwarder._bill_of_lading = {'failures': {}, 'successful': {}}
        commercial_invoice = self.freight_forwarder.commercial_invoice(
            action='deploy',
            data_center='local',
            environment='staging',
            transport_service=mock_transport_service()
        )
        mock_validate_commercial_invoice.return_value = commercial_invoice

        test_deployment = self.freight_forwarder.deploy_containers(
            commercial_invoice
        )

        # Ensure output of deployment is True based on no errors during the deployment process
        self.assertTrue(test_deployment)

        # Validate output of logging to ensure the correct host is output to the user
        calls = [call('Running deploy.'),
                 call('dispatching service: ffbug-example-tomcat-test on host: https://192.168.99.100:2376.')]
        mock_logger.info.assert_has_calls(calls)
 def test_valid_repository(self):
     self.assertRaises(TypeError, lambda: FreightForwarder(1, "cia"))
     self.assertRaises(TypeError, lambda: FreightForwarder([], "cia"))
     self.assertRaises(TypeError, lambda: FreightForwarder({}, "cia"))
     self.assertRaises(TypeError, lambda: FreightForwarder(None, "cia"))
     self.assertRaises(TypeError, lambda: FreightForwarder(type, "cia"))