Remove fuel_update_downloader from the repository

The development started a year ago, since then
there are no updates of plans. The code is not
finished and outdated, hence it's just removing
of unused code.

Change-Id: I385d12f6161a03b43ab820821141f07e6b1365b9
Related-bug: #1434106
This commit is contained in:
Evgeniy L 2015-03-19 17:16:06 +03:00
parent f173c600a8
commit b33726998e
14 changed files with 0 additions and 555 deletions

View File

@ -1,13 +0,0 @@
# Copyright 2014 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

View File

@ -1,76 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2014 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import argparse
import sys
import traceback
from fuel_update_downloader.downloader import Downloader
from fuel_update_downloader import errors
def handle_exception(exc):
if isinstance(exc, errors.FuelUpgradeException):
sys.stderr.write(exc.message + "\n")
sys.exit(-1)
else:
traceback.print_exc(exc)
sys.exit(-1)
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument(
'--src',
help='update url',
required=True)
parser.add_argument(
'--dst',
help='update path with update name',
required=True)
parser.add_argument(
'--checksum',
help='checksum of file',
required=True)
parser.add_argument(
'--size',
help='required free space for upgrade',
required=True,
type=int)
return parser.parse_args()
def run_upgrade(args):
"""Run upgrade on master node
"""
downloader = Downloader(
src_path=args.src,
dst_path=args.dst,
checksum=args.checksum,
required_free_space=args.size)
downloader.run()
def main():
"""Entry point
"""
try:
run_upgrade(parse_args())
except Exception as exc:
handle_exception(exc)

View File

@ -1,71 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2014 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from fuel_update_downloader import errors
from fuel_update_downloader.utils import calculate_free_space
from fuel_update_downloader.utils import calculate_md5sum
from fuel_update_downloader.utils import download_file
class Downloader(object):
"""Class implements downloading logic
"""
def __init__(self, src_path, dst_path, required_free_space, checksum):
"""Create downloader object
:param src_path: source path
:param dst_path: destination path
:param required_free_space: require free space
:param checksum: checksum of file
"""
self.src_path = src_path
self.dst_path = dst_path
self.required_free_space = required_free_space
self.checksum = checksum
def run(self):
"""Run downloading and checkings
"""
self._check_free_space()
download_file(self.src_path, self.dst_path)
self._check_checksum()
def _check_free_space(self):
"""Check `self.dst_path` free space
:raises: errors.NotEnoughFreeSpace
"""
free_space = calculate_free_space(self.dst_path)
if free_space < self.required_free_space:
raise errors.NotEnoughFreeSpace(
u'Not enough free space, path - "{0}", '
'free space - "{1}", '
'required free space - "{2}"'.format(
self.dst_path, free_space, self.required_free_space))
def _check_checksum(self):
"""Calculate checksum and compare it with `self.checksum`
:raises: errors.WrongChecksum
"""
calculated_checksum = calculate_md5sum(self.dst_path)
if calculated_checksum != self.checksum:
raise errors.WrongChecksum(
u'File "{0}" has wrong checkum, actual '
'checksum "{1}" expected checksum "{2}"'.format(
self.dst_path, calculated_checksum, self.checksum))

View File

@ -1,25 +0,0 @@
# Copyright 2014 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
class FuelUpgradeException(Exception):
pass
class NotEnoughFreeSpace(FuelUpgradeException):
pass
class WrongChecksum(FuelUpgradeException):
pass

View File

@ -1,15 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2014 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

View File

@ -1,27 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2014 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
try:
from unittest.case import TestCase
except ImportError:
# Required for python 2.6
from unittest2.case import TestCase
class BaseTestCase(TestCase):
"""Base class for test cases
"""
pass

View File

@ -1,76 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2014 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from mock import patch
from fuel_update_downloader import errors
from fuel_update_downloader.downloader import Downloader
from fuel_update_downloader.tests.base import BaseTestCase
@patch('fuel_update_downloader.downloader.download_file')
class TestDownloaderUnit(BaseTestCase):
def default_args(self, **kwargs):
default = {
'src_path': 'file:///tmp/src_file',
'dst_path': '/tmp/dst_file',
'required_free_space': 100,
'checksum': ''}
default.update(kwargs)
return default
@patch(
'fuel_update_downloader.downloader.calculate_free_space',
return_value=101)
@patch(
'fuel_update_downloader.downloader.calculate_md5sum',
return_value='')
def test_run_without_errors(self, _, __, ___):
downloader = Downloader(**self.default_args())
downloader.run()
def test_run_error_in_case_if_disk_does_not_have_enough_space(self, _):
kwargs = self.default_args(required_free_space=1000)
downloader = Downloader(**kwargs)
with patch(
'fuel_update_downloader.downloader.calculate_free_space',
return_value=1):
self.assertRaisesRegexp(
errors.NotEnoughFreeSpace,
'Not enough free space, path - "/tmp/dst_file", '
'free space - "1", required free space - "1000"',
downloader.run)
def test_run_error_in_case_if_md5_sums_are_not_equal(
self, download_file_mock):
kwargs = self.default_args(required_free_space=1000)
downloader = Downloader(**kwargs)
with patch(
'fuel_update_downloader.downloader.calculate_md5sum',
return_value='wrong_md5_sum'):
self.assertRaisesRegexp(
errors.WrongChecksum,
'File "/tmp/dst_file" has wrong checkum, actual '
'checksum "wrong_md5_sum" expected checksum ""',
downloader.run)

View File

@ -1,87 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2014 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
import mock
from mock import patch
from StringIO import StringIO
from fuel_update_downloader.tests.base import BaseTestCase
from fuel_update_downloader.utils import byte_to_megabyte
from fuel_update_downloader.utils import calculate_free_space
from fuel_update_downloader.utils import calculate_md5sum
from fuel_update_downloader.utils import download_file
class FakeFile(StringIO):
"""It's a fake file which returns StringIO
when file opens with 'with' statement.
NOTE(eli): We cannot use mock_open from mock library
here, because it hangs when we use 'with' statement,
and when we want to read file by chunks.
"""
def __enter__(self):
return self
def __exit__(self, *args):
pass
class TestUtils(BaseTestCase):
def test_byte_to_megabyte(self):
self.assertEqual(byte_to_megabyte(0), 0)
self.assertEqual(byte_to_megabyte(1048576), 1)
def test_calculate_free_space(self):
dev_info = mock.Mock()
dev_info.f_bsize = 1048576
dev_info.f_bavail = 2
with patch.object(os, 'statvfs', return_value=dev_info) as st_mock:
self.assertEqual(calculate_free_space('/tmp/dir/file'), 2)
st_mock.assert_called_once_with('/tmp/dir')
def test_calculate_md5sum(self):
open_mock = mock.MagicMock(return_value=FakeFile('fake file content'))
file_path = '/tmp/file'
with mock.patch('__builtin__.open', open_mock):
self.assertEqual(
calculate_md5sum(file_path),
'199df6f47108545693b5c9cb5344bf13')
open_mock.assert_called_once_with(file_path, 'rb')
def test_download_file(self):
content = 'Some content'
fake_src = StringIO(content)
fake_file = FakeFile('')
file_mock = mock.MagicMock(return_value=fake_file)
src_path = 'http://0.0.0.0:80/tmp/file'
dst_path = '/tmp/file'
with mock.patch('urllib2.urlopen', return_value=fake_src) as url_fake:
with mock.patch('__builtin__.open', file_mock):
download_file(src_path, dst_path)
file_mock.assert_called_once_with(dst_path, 'wb')
url_fake.assert_called_once_with(src_path)
self.assertEqual(fake_file.getvalue(), content)

View File

@ -1,63 +0,0 @@
# Copyright 2014 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import hashlib
import os
import urllib2
def download_file(src, dst, chunk_size=2 ** 20):
"""Download file
:param src: download from
:param dst: download to
:param chunk_size: optional parameter, size of chunk
"""
with open(dst, 'wb') as f:
for chunk in urllib2.urlopen(src).read(chunk_size):
f.write(chunk)
def calculate_md5sum(file_path, chunk_size=2 ** 20):
"""Calculate file's checksum
:param file_path: file path
:param chunk_size: optional parameter, size of chunk
:returns: md5sum string
"""
# TODO(el): maybe it will be much faster to use
# linux md5sum command line utility
md5 = hashlib.md5()
with open(file_path, 'rb') as f:
for chunk in iter(lambda: f.read(chunk_size), b''):
md5.update(chunk)
return md5.hexdigest()
def calculate_free_space(path):
"""Calculate free space
:returns: free space in megabytes
"""
directory = os.path.dirname(path)
device_info = os.statvfs(directory)
return byte_to_megabyte(device_info.f_bsize * device_info.f_bavail)
def byte_to_megabyte(byte):
"""Convert bytes to megabytes
"""
return byte / 1024 ** 2

View File

@ -1,2 +0,0 @@
argparse==1.2.1
PyYAML==3.10

View File

@ -1,48 +0,0 @@
# Copyright 2014 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
import os.path
from setuptools import find_packages
from setuptools import setup
def find_requires():
dir_path = os.path.dirname(os.path.realpath(__file__))
requirements = []
with open(u'{0}/requirements.txt'.format(dir_path), 'r') as reqs:
requirements = reqs.readlines()
return requirements
if __name__ == "__main__":
setup(name='fuel_update_downloader',
version='0.1.0',
description='Updates downloader for Fuel-master node',
long_description="""Updates downloader for Fuel-master node""",
classifiers=[
"Programming Language :: Python",
"Topic :: System :: Software Distribution"],
author='Mirantis Inc.',
author_email='product@mirantis.com',
url='http://mirantis.com',
keywords='fuel download upgrade mirantis',
packages=find_packages(),
zip_safe=False,
install_requires=find_requires(),
include_package_data=True,
entry_points={
'console_scripts': [
'fuel-update-downloader = fuel_update_downloader.cli:main']})

View File

@ -1,6 +0,0 @@
-r requirements.txt
hacking==0.7
mock==1.0
nose==1.1.2
nose2==0.4.1
nose-timer==0.2.0

View File

@ -1,38 +0,0 @@
[tox]
minversion = 1.6
skipsdist = True
envlist = py26,py27,pep8
[testenv]
usedevelop = True
install_command = pip install --allow-external -U {opts} {packages}
setenv = VIRTUAL_ENV={envdir}
deps = -r{toxinidir}/test-requirements.txt
commands =
nosetests {posargs:fuel_update_downloader}
[tox:jenkins]
downloadcache = ~/cache/pip
[testenv:pep8]
deps = hacking==0.7
usedevelop = False
commands =
flake8 {posargs:.}
[testenv:venv]
commands = {posargs:}
[testenv:devenv]
envdir = devenv
usedevelop = True
[flake8]
ignore = H234,H302,H802
exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build,tools,__init__.py,docs
show-pep8 = True
show-source = True
count = True
[hacking]
import_exceptions = testtools.matchers

View File

@ -89,7 +89,6 @@ testropts="--with-timer --timer-warning=10 --timer-ok=2 --timer-top-n=10"
# nosetest xunit options
NAILGUN_XUNIT=${NAILGUN_XUNIT:-"$ROOT/nailgun.xml"}
FUELUPGRADE_XUNIT=${FUELUPGRADE_XUNIT:-"$ROOT/fuelupgrade.xml"}
FUELUPGRADEDOWNLOADER_XUNIT=${FUELUPGRADEDOWNLOADER_XUNIT:-"$ROOT/fuelupgradedownloader.xml"}
SHOTGUN_XUNIT=${SHOTGUN_XUNIT:-"$ROOT/shotgun.xml"}
UI_SERVER_PORT=${UI_SERVER_PORT:-5544}
NAILGUN_PORT=${NAILGUN_PORT:-8003}
@ -345,8 +344,6 @@ function run_webui_tests {
# $@ -- tests to be run; with no arguments all tests will be run
function run_upgrade_system_tests {
local UPGRADE_TESTS="$ROOT/fuel_upgrade_system/fuel_upgrade/fuel_upgrade/tests/"
local DOWNLOADER_TESTS="$ROOT/fuel_upgrade_system/fuel_update_downloader/fuel_update_downloader/tests/"
local result=0
if [ $# -ne 0 ]; then
@ -359,10 +356,6 @@ function run_upgrade_system_tests {
tox -epy26 -- -vv $testropts $UPGRADE_TESTS --xunit-file $FUELUPGRADE_XUNIT || result=1
popd >> /dev/null
pushd $ROOT/fuel_upgrade_system/fuel_update_downloader >> /dev/null
tox -epy26 -- -vv $testropts $DOWNLOADER_TESTS --xunit-file $FUELUPGRADEDOWNLOADER_XUNIT || result=1
popd >> /dev/null
fi
return $result
@ -424,7 +417,6 @@ function run_flake8 {
run_flake8_subproject tasklib && \
run_flake8_subproject fuelmenu && \
run_flake8_subproject network_checker && \
run_flake8_subproject fuel_upgrade_system/fuel_update_downloader && \
run_flake8_subproject fuel_upgrade_system/fuel_upgrade && \
run_flake8_subproject fuel_development && \
run_flake8_subproject shotgun || result=1