Esempio n. 1
0
def test_service_creator_initial_config(sonic_fs, manifest,
                                        mock_feature_registry, mock_sonic_db):
    mock_table = Mock()
    mock_table.get = Mock(return_value=(True, (('field_2',
                                                'original_value_2'), )))
    mock_sonic_db.initial_table = Mock(return_value=mock_table)
    mock_sonic_db.persistent_table = Mock(return_value=mock_table)
    mock_sonic_db.running_table = Mock(return_value=mock_table)

    creator = ServiceCreator(mock_feature_registry, mock_sonic_db)

    entry = PackageEntry('test', 'azure/sonic-test')
    package = Package(entry, Metadata(manifest))
    creator.create(package)

    assert not sonic_fs.exists(os.path.join(DEBUG_DUMP_SCRIPT_LOCATION,
                                            'test'))

    manifest['package']['init-cfg'] = {
        'TABLE_A': {
            'key_a': {
                'field_1': 'value_1',
                'field_2': 'value_2'
            },
        },
    }
    package = Package(entry, Metadata(manifest))

    creator.create(package)
    mock_table.set.assert_called_with('key_a',
                                      [('field_1', 'value_1'),
                                       ('field_2', 'original_value_2')])

    creator.remove(package)
    mock_table._del.assert_called_with('key_a')
def test_service_creator_with_timer_unit(sonic_fs, manifest, service_creator):
    entry = PackageEntry('test', 'azure/sonic-test')
    package = Package(entry, Metadata(manifest))
    service_creator.create(package)

    assert not sonic_fs.exists(os.path.join(SYSTEMD_LOCATION, 'test.timer'))

    manifest['service']['delayed'] = True
    package = Package(entry, Metadata(manifest))
    service_creator.create(package)

    assert sonic_fs.exists(os.path.join(SYSTEMD_LOCATION, 'test.timer'))
def test_service_creator_with_debug_dump(sonic_fs, manifest, service_creator):
    entry = PackageEntry('test', 'azure/sonic-test')
    package = Package(entry, Metadata(manifest))
    service_creator.create(package)

    assert not sonic_fs.exists(os.path.join(DEBUG_DUMP_SCRIPT_LOCATION, 'test'))

    manifest['package']['debug-dump'] = '/some/command'
    package = Package(entry, Metadata(manifest))
    service_creator.create(package)

    assert sonic_fs.exists(os.path.join(DEBUG_DUMP_SCRIPT_LOCATION, 'test'))
def test_service_creator_yang(sonic_fs, manifest, mock_sonic_db,
                              mock_config_mgmt, service_creator):
    test_yang = 'TEST YANG'
    test_yang_module = 'sonic-test'

    mock_connector = Mock()
    mock_sonic_db.get_connectors = Mock(return_value=[mock_connector])
    mock_connector.get_table = Mock(
        return_value={'key_a': {
            'field_1': 'value_1'
        }})
    mock_connector.get_config = Mock(
        return_value={
            'TABLE_A': mock_connector.get_table(''),
            'TABLE_B': mock_connector.get_table(''),
            'TABLE_C': mock_connector.get_table(''),
        })

    entry = PackageEntry('test', 'azure/sonic-test')
    package = Package(entry, Metadata(manifest, yang_module_str=test_yang))
    service_creator.create(package)

    mock_config_mgmt.add_module.assert_called_with(test_yang)
    mock_config_mgmt.get_module_name = Mock(return_value=test_yang_module)

    manifest['package']['init-cfg'] = {
        'TABLE_A': {
            'key_a': {
                'field_1': 'new_value_1',
                'field_2': 'value_2'
            },
        },
    }
    package = Package(entry, Metadata(manifest, yang_module_str=test_yang))

    service_creator.create(package)

    mock_config_mgmt.add_module.assert_called_with(test_yang)

    mock_connector.mod_entry.assert_called_once_with('TABLE_A', 'key_a', {
        'field_1': 'value_1',
        'field_2': 'value_2'
    })

    mock_config_mgmt.sy.confDbYangMap = {
        'TABLE_A': {
            'module': test_yang_module
        }
    }

    service_creator.remove(package)
    mock_connector.set_entry.assert_called_with('TABLE_A', 'key_a', None)
    mock_config_mgmt.remove_module.assert_called_with(test_yang_module)
Esempio n. 5
0
 def from_local(self, image: str):
     ref = Reference.parse(image)
     manifest = Manifest.marshal(
         self.metadata_store[ref['name']][ref['tag']]['manifest'])
     components = self.metadata_store[ref['name']][
         ref['tag']]['components']
     return Metadata(manifest, components)
def test_service_creator_autocli(sonic_fs, manifest, mock_cli_gen,
                                 mock_config_mgmt, service_creator):
    test_yang = 'TEST YANG'
    test_yang_module = 'sonic-test'

    manifest['cli']['auto-generate-show'] = True
    manifest['cli']['auto-generate-config'] = True

    entry = PackageEntry('test', 'azure/sonic-test')
    package = Package(entry, Metadata(manifest, yang_module_str=test_yang))
    mock_config_mgmt.get_module_name = Mock(return_value=test_yang_module)
    service_creator.create(package)

    mock_cli_gen.generate_cli_plugin.assert_has_calls(
        [
            call('show', test_yang_module),
            call('config', test_yang_module),
        ],
        any_order=True
    )

    service_creator.remove(package)
    mock_cli_gen.remove_cli_plugin.assert_has_calls(
        [
            call('show', test_yang_module),
            call('config', test_yang_module),
        ],
        any_order=True
    )
Esempio n. 7
0
 def from_tarball(self, filepath: str) -> Manifest:
     path, ref = filepath.split(':')
     manifest = Manifest.marshal(
         self.metadata_store[path][ref]['manifest'])
     components = self.metadata_store[path][ref]['components']
     yang = self.metadata_store[path][ref]['yang']
     return Metadata(manifest, components, yang)
Esempio n. 8
0
 def from_registry(self, repository: str, reference: str):
     manifest = Manifest.marshal(
         self.metadata_store[repository][reference]['manifest'])
     components = self.metadata_store[repository][reference][
         'components']
     yang = self.metadata_store[repository][reference]['yang']
     return Metadata(manifest, components, yang)
def test_service_creator(sonic_fs, manifest, mock_feature_registry,
                         mock_sonic_db):
    creator = ServiceCreator(mock_feature_registry, mock_sonic_db)
    entry = PackageEntry('test', 'azure/sonic-test')
    package = Package(entry, Metadata(manifest))
    creator.create(package)

    assert sonic_fs.exists(os.path.join(ETC_SONIC_PATH, 'swss_dependent'))
    assert sonic_fs.exists(os.path.join(DOCKER_CTL_SCRIPT_LOCATION, 'test.sh'))
    assert sonic_fs.exists(
        os.path.join(SERVICE_MGMT_SCRIPT_LOCATION, 'test.sh'))
    assert sonic_fs.exists(os.path.join(SYSTEMD_LOCATION, 'test.service'))
def test_service_creator(sonic_fs, manifest, service_creator, package_manager):
    entry = PackageEntry('test', 'azure/sonic-test')
    package = Package(entry, Metadata(manifest))
    installed_packages = package_manager._get_installed_packages_and(package)
    service_creator.create(package)
    service_creator.generate_shutdown_sequence_files(installed_packages)

    assert sonic_fs.exists(os.path.join(ETC_SONIC_PATH, 'swss_dependent'))
    assert sonic_fs.exists(os.path.join(DOCKER_CTL_SCRIPT_LOCATION, 'test.sh'))
    assert sonic_fs.exists(os.path.join(SERVICE_MGMT_SCRIPT_LOCATION, 'test.sh'))
    assert sonic_fs.exists(os.path.join(SYSTEMD_LOCATION, 'test.service'))

    def read_file(name):
        with open(os.path.join(ETC_SONIC_PATH, name)) as file:
            return file.read()

    assert read_file('warm-reboot_order') == 'swss teamd test syncd'
    assert read_file('fast-reboot_order') == 'teamd test swss syncd'
    assert read_file('test_reconcile') == 'test-process test-process-3'