コード例 #1
0
 def setUp(self):
     DatabaseIDModel.objects.create()
     InstanceIDModel.get_or_create_current_instance()
     self.range = 10
     self.mc = MorangoProfileController('facilitydata')
     self.original_name = "ralphie"
     self.new_name = "rafael"
コード例 #2
0
    def setUp(self):
        self.profile = "facilitydata"

        self.root_scope_def = ScopeDefinition.objects.create(
            id="rootcert",
            profile=self.profile,
            version=1,
            primary_scope_param_key="mainpartition",
            description="Root cert for ${mainpartition}.",
            read_filter_template="",
            write_filter_template="",
            read_write_filter_template="${mainpartition}",
        )

        self.subset_scope_def = ScopeDefinition.objects.create(
            id="subcert",
            profile=self.profile,
            version=1,
            primary_scope_param_key="",
            description=
            "Subset cert under ${mainpartition} for ${subpartition}.",
            read_filter_template="${mainpartition}",
            write_filter_template="${mainpartition}:${subpartition}",
            read_write_filter_template="",
        )

        self.root_cert = Certificate.generate_root_certificate(
            self.root_scope_def.id)

        self.subset_cert = Certificate(
            parent=self.root_cert,
            profile=self.profile,
            scope_definition=self.subset_scope_def,
            scope_version=self.subset_scope_def.version,
            scope_params=json.dumps({
                "mainpartition": self.root_cert.id,
                "subpartition": "abracadabra"
            }),
            private_key=Key(),
        )
        self.root_cert.sign_certificate(self.subset_cert)
        self.subset_cert.save()

        self.unsaved_cert = Certificate(
            parent=self.root_cert,
            profile=self.profile,
            scope_definition=self.subset_scope_def,
            scope_version=self.subset_scope_def.version,
            scope_params=json.dumps({
                "mainpartition": self.root_cert.id,
                "subpartition": "other"
            }),
            public_key=Key(),
        )
        self.root_cert.sign_certificate(self.unsaved_cert)

        self.controller = MorangoProfileController('facilitydata')
        self.network_connection = self.controller.create_network_connection(
            self.live_server_url)
        self.key = SharedKey.get_or_create_shared_key()
コード例 #3
0
 def setUp(self):
     DatabaseIDModel.objects.create()
     (self.current_id, _) = InstanceIDModel.get_or_create_current_instance()
     self.mc = MorangoProfileController('facilitydata')
     self.fac1 = FacilityModelFactory(name='school')
     self.mc.serialize_into_store()
     self.old_rmc = RecordMaxCounter.objects.first()
コード例 #4
0
ファイル: fullfacilitysync.py プロジェクト: willingc/kolibri
    def handle_async(self, *args, **options):
        # call this in case user directly syncs without migrating database
        if not ScopeDefinition.objects.filter():
                call_command("loaddata", "scopedefinitions")
        controller = MorangoProfileController('facilitydata')
        with self.start_progress(total=7) as progress_update:
            network_connection = controller.create_network_connection(options['base_url'])
            progress_update(1)

            options['dataset_id'] = self.get_dataset_id(options['base_url'], options['dataset_id'])
            progress_update(1)

            client_cert, server_cert = self.get_client_and_server_certs(options['username'], options['password'],
                                                                        options['dataset_id'], network_connection)
            progress_update(1)

            sync_client = network_connection.create_sync_session(client_cert, server_cert)
            progress_update(1)

            # pull from server and push our own data to server
            if not options['no_pull']:
                sync_client.initiate_pull(Filter(options['dataset_id']))
            if not options['no_push']:
                sync_client.initiate_push(Filter(options['dataset_id']))
            progress_update(1)

            self.create_superuser_and_provision_device(options['username'], options['dataset_id'])
            progress_update(1)

            sync_client.close_sync_session()
            progress_update(1)
コード例 #5
0
 def setUp(self):
     (self.current_id, _) = InstanceIDModel.get_or_create_current_instance()
     self.range = 10
     self.mc = MorangoProfileController('facilitydata')
     for i in range(self.range):
         self.ident = uuid.uuid4().hex
         StoreModelFacilityFactory(pk=self.ident,
                                   serialized=serialized_facility_factory(
                                       self.ident))
コード例 #6
0
def create_dummy_store_data():
    data = {}
    DatabaseIDModel.objects.create()
    (data['group1_id'], _) = InstanceIDModel.get_or_create_current_instance()  # counter is at 0

    # create controllers for app/store/buffer operations
    data['mc'] = MorangoProfileController('facilitydata')
    data['sc'] = SyncClient(None, 'host')
    session = SyncSession.objects.create(id=uuid.uuid4().hex, profile="facilitydata", last_activity_timestamp=timezone.now())
    data['sc'].current_transfer_session = TransferSession.objects.create(id=uuid.uuid4().hex, sync_session=session, push=True, last_activity_timestamp=timezone.now())

    data['mc'].serialize_into_store()  # counter is at 1
    # create group of facilities and first serialization
    data['group1_c1'] = [FacilityFactory() for _ in range(5)]
    data['mc'].serialize_into_store()  # counter is at 2

    # create group of facilities and second serialization
    data['group1_c2'] = [FacilityFactory() for _ in range(5)]

    # create users and logs associated with user
    data['user1'] = MyUser.objects.create(username='******')
    data['user1_sumlogs'] = [SummaryLog.objects.create(user=data['user1']) for _ in range(5)]

    data['mc'].serialize_into_store()  # counter is at 3

    # create new instance id and group of facilities
    with mock.patch('platform.platform', return_value='plataforma'):
        (data['group2_id'], _) = InstanceIDModel.get_or_create_current_instance()  # new counter is at 0

    data['mc'].serialize_into_store()  # new counter is at 1
    data['group2_c1'] = [FacilityFactory() for _ in range(5)]

    # create users and logs associated with user
    data['user2'] = MyUser.objects.create(username='******')
    data['user2_sumlogs'] = [SummaryLog.objects.create(user=data['user2']) for _ in range(5)]
    data['user2_interlogs'] = [InteractionLog.objects.create(user=data['user2']) for _ in range(5)]

    data['user3'] = MyUser.objects.create(username='******')
    data['user3_sumlogs'] = [SummaryLog.objects.create(user=data['user3']) for _ in range(5)]
    data['user3_interlogs'] = [InteractionLog.objects.create(user=data['user3']) for _ in range(5)]

    data['mc'].serialize_into_store()  # new counter is at 2

    data['user4'] = MyUser.objects.create(username='******', _morango_partition='badpartition')
    data['mc'].serialize_into_store()  # new counter is at 3

    return data
コード例 #7
0
    def setUp(self):
        settings.MORANGO_DESERIALIZE_AFTER_DEQUEUING = False
        self.data = {}
        DatabaseIDModel.objects.create()
        (self.current_id, _) = InstanceIDModel.get_or_create_current_instance()

        # create controllers for app/store/buffer operations
        self.data['mc'] = MorangoProfileController('facilitydata')
        self.data['sc'] = SyncClient(None, 'host')
        session = SyncSession.objects.create(
            id=uuid.uuid4().hex,
            profile="",
            last_activity_timestamp=timezone.now())
        self.data[
            'sc'].current_transfer_session = TransferSession.objects.create(
                id=uuid.uuid4().hex,
                sync_session=session,
                push=True,
                last_activity_timestamp=timezone.now())
        self.data.update(
            create_buffer_and_store_dummy_data(
                self.data['sc'].current_transfer_session.id))
コード例 #8
0
 def setUp(self):
     (self.current_id, _) = InstanceIDModel.get_or_create_current_instance()
     self.mc = MorangoProfileController('facilitydata')
コード例 #9
0
 def setUp(self):
     self.controller = MorangoProfileController('facilitydata')
     InstanceIDModel.get_or_create_current_instance()
コード例 #10
0
ファイル: sync.py プロジェクト: wuyeh-jobe/kolibri
    def handle_async(self, *args, **options):

        baseurl = options["baseurl"]
        facility_id = options["facility"]
        chunk_size = options["chunk_size"]

        # This handles the case for when we want to pull in facility data for our empty kolibri instance
        if not facility_id:
            self._fullfacilitysync(baseurl)

        facility = get_facility(
            facility_id=facility_id, noninteractive=options["noninteractive"]
        )

        # if url is not pointing to portal server, do P2P syncing
        self._fullfacilitysync(baseurl, facility=facility, chunk_size=chunk_size)

        # data portal syncing
        self.stdout.write("Syncing has been initiated (this may take a while)...")
        controller = MorangoProfileController("facilitydata")
        with self.start_progress(total=5) as progress_update:
            try:
                network_connection = controller.create_network_connection(baseurl)
            except ConnectionError as e:
                raise CommandError(e)
            progress_update(1)

            # get client certificate
            client_cert = (
                facility.dataset.get_owned_certificates()
                .filter(scope_definition_id=FULL_FACILITY)
                .first()
            )
            if not client_cert:
                raise CommandError(
                    "This device does not own a certificate for Facility: {}".format(
                        facility.name
                    )
                )

            # push certificate up to portal server
            scope_params = json.loads(client_cert.scope_params)
            server_cert = network_connection.push_signed_client_certificate_chain(
                local_parent_cert=client_cert,
                scope_definition_id=FULL_FACILITY,
                scope_params=scope_params,
            )
            progress_update(1)

            # we should now be able to push our facility data
            sync_client = network_connection.create_sync_session(
                client_cert, server_cert, chunk_size=chunk_size
            )
            progress_update(1)

            sync_client.initiate_push(Filter(scope_params["dataset_id"]))
            progress_update(1)

            sync_client.close_sync_session()
            progress_update(1)
            self.stdout.write("Syncing has been completed.")
コード例 #11
0
    def handle_async(self, *args, **options):
        # validate url that is passed in
        try:
            URLValidator()((options['base_url']))
        except ValidationError:
            print(
                'Base-url is not valid. Please retry command and enter a valid url.'
            )
            sys.exit(1)

        # call this in case user directly syncs without migrating database
        if not ScopeDefinition.objects.filter():
            call_command("loaddata", "scopedefinitions")

        # ping server at url with info request
        info_url = urljoin(options['base_url'],
                           'api/morango/v1/morangoinfo/1/')
        try:
            info_resp = requests.get(info_url)
        except ConnectionError:
            print('Can not connect to server with base-url: {}'.format(
                options['base_url']))
            sys.exit(1)

        # if instance_ids are equal, this means device is trying to sync with itself, which we don't allow
        if InstanceIDModel.get_or_create_current_instance(
        )[0].id == info_resp.json()['instance_id']:
            print(
                'Device can not sync with itself. Please re-check base-url and try again.'
            )
            sys.exit(1)

        controller = MorangoProfileController('facilitydata')
        with self.start_progress(total=7) as progress_update:
            network_connection = controller.create_network_connection(
                options['base_url'])
            progress_update(1)

            options['dataset_id'] = self.get_dataset_id(
                options['base_url'], options['dataset_id'])
            progress_update(1)

            client_cert, server_cert, options[
                'username'] = self.get_client_and_server_certs(
                    options['username'], options['password'],
                    options['dataset_id'], network_connection)
            progress_update(1)

            sync_client = network_connection.create_sync_session(
                client_cert, server_cert)
            progress_update(1)

            # pull from server and push our own data to server
            if not options['no_pull']:
                sync_client.initiate_pull(Filter(options['dataset_id']))
            if not options['no_push']:
                sync_client.initiate_push(Filter(options['dataset_id']))
            progress_update(1)

            self.create_superuser_and_provision_device(options['username'],
                                                       options['dataset_id'])
            progress_update(1)

            sync_client.close_sync_session()
            progress_update(1)
コード例 #12
0
ファイル: test_signals.py プロジェクト: edulution/morango
 def setUp(self):
     DatabaseIDModel.objects.create()
     InstanceIDModel.get_or_create_current_instance()
     [FacilityModelFactory() for _ in range(10)]
     self.mc = MorangoProfileController('facilitydata')
     self.mc.serialize_into_store()
コード例 #13
0
    def handle_async(self, *args, **options):
        # validate url that is passed in
        try:
            URLValidator()((options["base_url"]))
        except ValidationError:
            raise CommandError(
                "Base URL is not valid. Please retry command and enter a valid URL."
            )

        # call this in case user directly syncs without migrating database
        if not ScopeDefinition.objects.filter():
            call_command("loaddata", "scopedefinitions")

        controller = MorangoProfileController("facilitydata")
        with self.start_progress(total=7) as progress_update:
            try:
                network_connection = controller.create_network_connection(
                    options["base_url"])
            except ConnectionError:
                raise CommandError(
                    "Can not connect to server with base URL: {}".format(
                        options["base_url"]))

            # if instance_ids are equal, this means device is trying to sync with itself, which we don't allow
            if (InstanceIDModel.get_or_create_current_instance()[0].id ==
                    network_connection.server_info["instance_id"]):
                raise CommandError(
                    "Device can not sync with itself. Please recheck base URL and try again."
                )

            progress_update(1)

            options["dataset_id"] = self.get_dataset_id(
                options["base_url"], options["dataset_id"])
            progress_update(1)

            client_cert, server_cert, options[
                "username"] = self.get_client_and_server_certs(
                    options["username"],
                    options["password"],
                    options["dataset_id"],
                    network_connection,
                )
            progress_update(1)

            sync_client = network_connection.create_sync_session(
                client_cert, server_cert, chunk_size=options["chunk_size"])
            progress_update(1)

            # pull from server and push our own data to server
            if not options["no_pull"]:
                sync_client.initiate_pull(Filter(options["dataset_id"]))
            if not options["no_push"]:
                sync_client.initiate_push(Filter(options["dataset_id"]))
            progress_update(1)

            self.create_superuser_and_provision_device(options["username"],
                                                       options["dataset_id"])
            progress_update(1)

            sync_client.close_sync_session()
            progress_update(1)