def test_spacewalk_sync(self):
        mocked_sw_client_class = self.mock(checkin, 'SpacewalkClient')
        mocked_sw_client = Mock()
        mocked_sw_client_class.return_value = mocked_sw_client
        mocked_cp_client_class = self.mock(checkin, 'KatelloConnection')
        mocked_cp_client = Mock()
        mocked_cp_client_class.return_value = mocked_cp_client

        mocked_sw_client.get_user_list.return_value = user_list
        mocked_sw_client.get_system_list.return_value = system_list
        mocked_sw_client.get_channel_list.return_value = channel_list
        mocked_sw_client.get_org_list.return_value = org_list

        mocked_cp_client.getOwners.return_value = owner_list
        mocked_cp_client.getRedhatProvider.return_value = provider
        mocked_cp_client.getRoles.return_value = role_list
        mocked_cp_client.getUsers.return_value = cp_user_list
        mocked_cp_client.getConsumers.return_value = consumer_list
        
        options = Mock()
        delete_stale_consumers = self.mock(checkin, 'delete_stale_consumers')
        upload_to_cp = self.mock(checkin, 'upload_to_katello')

        checkin.spacewalk_sync(options)

        # base channel was set to RH channel
        self.assertEquals('rhel-x86_64-server-6',
                          system_list[1]['software_channel'])
        self.assertTrue(delete_stale_consumers.called)
        self.assertTrue(system_list[0].has_key('installed_products'))
        self.assertTrue(system_list[1].has_key('installed_products'))
        self.assertTrue(upload_to_cp.called)
        self.assertEquals(2, len(upload_to_cp.call_args[0][0]))
Exemplo n.º 2
0
    def test_spacewalk_sync(self):
        mocked_sw_client_class = self.mock(checkin, 'SpacewalkClient')
        mocked_sw_client = Mock()
        mocked_sw_client.prefix = ""
        mocked_sw_client_class.return_value = mocked_sw_client
        mocked_cp_client_class = self.mock(checkin, 'KatelloConnection')
        mocked_cp_client = Mock()
        mocked_cp_client_class.return_value = mocked_cp_client

        mocked_certdir_class = self.mock(checkin, 'CertificateDirectory')
        mocked_certdir = Mock()

        mock_products = Mock()
        mock_products.products = Mock()
        mock_product = Mock()
        mock_product.id = 123
        mock_product.name = 'some product'
        mock_products.products = [mock_product]
        mocked_certdir.findByProduct.return_value = mock_products
        mocked_certdir_class.return_value = mocked_certdir

        mocked_sw_client.get_user_list.return_value = user_list
        mocked_sw_client.get_system_list.return_value = system_list
        mocked_sw_client.get_channel_list.return_value = channel_list
        mocked_sw_client.get_org_list.return_value = org_list
        # this should be populated eventually
        mocked_sw_client.get_host_guest_list.return_value = []

        mocked_cp_client.get_owners.return_value = owner_list
        mocked_cp_client.get_redhat_provider.return_value = provider
        mocked_cp_client.get_roles.return_value = role_list
        mocked_cp_client.get_users.return_value = cp_user_list
        mocked_cp_client.get_consumers.return_value = consumer_list
        
        options = Mock()
        delete_stale_consumers = self.mock(katello_sync.KatelloPushSync, 'delete_stale_consumers')
        upload_to_cp = self.mock(katello_sync.KatelloPushSync, 'upload_to_katello')
        autoentitle = self.mock(katello_sync.KatelloPushSync, 'autoentitle_satellite_orgs')

        checkin.spacewalk_sync(options)
        # single SW, ensure we only initailized one sw client class
        self.assertEquals(1, mocked_sw_client_class.call_count)

        # base channel was set to RH channel
        self.assertEquals('rhel-x86_64-server-6',
                          system_list[1]['software_channel'])
        # test BZ 1064523
        self.assertEquals('rhel-x86_64-server-6;some-other-channel',
                          system_list[2]['software_channel'])
        self.assertTrue(delete_stale_consumers.called)
        self.assertTrue(autoentitle.called)
        self.assertTrue(system_list[0].has_key('installed_products'))
        self.assertTrue(system_list[1].has_key('installed_products'))
        self.assertTrue(upload_to_cp.called)
        self.assertEquals(3, len(upload_to_cp.call_args[0][0]))
Exemplo n.º 3
0
    def test_ssh_plus_localfile_sw_sync(self, mocked_utils):
        # check that we create two SpacewalkClients for multiple input dirs
        # TODO: factor out these setup steps
        options = Mock()
        self.unmock_config()
        self.mock_config(multisw=True)
        options.spacewalk_sync = True
        mocked_sw_client_class = self.mock(checkin, 'SpacewalkClient')
        mocked_sw_client = Mock()
        mocked_sw_client_class.return_value = mocked_sw_client
        mocked_sw_client.get_org_list.return_value = org_list
        mocked_sw_client.get_user_list.return_value = user_list
        mocked_sw_client.get_system_list.return_value = system_list
        mocked_sw_client.get_channel_list.return_value = channel_list
        mocked_sw_client.get_host_guest_list.return_value = []
        mocked_sw_client.prefix = "someprefix"


        mocked_cp_client_class = self.mock(checkin, 'KatelloConnection')
        mocked_cp_client = Mock()
        mocked_cp_client_class.return_value = mocked_cp_client
        mocked_cp_client.get_owners.return_value = owner_list
        mocked_cp_client.get_redhat_provider.return_value = provider
        mocked_cp_client.get_roles.return_value = role_list
        mocked_cp_client.get_users.return_value = cp_user_list
        mocked_cp_client.get_consumers.return_value = consumer_list


        checkin.spacewalk_sync(options)


        self.assertEquals(3, mocked_sw_client_class.call_count)
        # the order of calls can get swapped, since it's based on reading a dict
        self.assertTrue(call(local_dir='/path/to/report', prefix='bar') in mocked_sw_client_class.mock_calls[:3])
        self.assertTrue(call(ssh_key_path='spacewalk_ssh_key_path', login='******', host='spacewalkhost', prefix='baz') in
                        mocked_sw_client_class.mock_calls[:3])
        self.assertTrue(call(ssh_key_path='spacewalk_ssh_key_path', login='******', host='spacewalkhost', prefix='foo') in
                        mocked_sw_client_class.mock_calls[:3])