Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible issue with archive.tar #7244

Closed
phpcool opened this issue Sep 14, 2013 · 16 comments
Closed

Possible issue with archive.tar #7244

phpcool opened this issue Sep 14, 2013 · 16 comments
Labels
Bug broken, incorrect, or confusing behavior
Milestone

Comments

@phpcool
Copy link

phpcool commented Sep 14, 2013

I found a bug in salt.modules.archive.

when i run "salt 'clent' archive.tar czf /home/tarfile.tar.gz /etc"
return this message:
clent:
- tar: Cowardly refusing to create an empty archive
- Try tar --help' ortar --usage' for more information.

I edited “/usr/lib/python2.6/site-packages/salt/modules/archive.py” file.it is OK now.

- def tar(options, tarfile, cwd=None, template=None, *sources):

  • def tar(options, tarfile, sources, cwd=None, template=None):

+ import string

  • _sources=string.split(sources,',')
  • sourcefiles = ' '.join(_sources)
  • sourcefiles = ' '.join(sources)
    

and zip function also have the same problem.

@s0undt3ch
Copy link
Collaborator

If you run the tests suite with your changes, you'll notice that is will not pass. Code similar to yours was already removed, see here.

@s0undt3ch
Copy link
Collaborator

Here's a simple example why:

>>> def foo(a, b, options=None, *args):
...     print 'A', a
...     print 'B', b
...     print 'options', options
...     print 'args', args
... 
>>> foo(1, 2, 3)
A 1
B 2
options 3
args ()
>>> foo(1, 2, options=3)
A 1
B 2
options 3
args ()
>>> foo(1, 2, 4, options=3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: foo() got multiple values for keyword argument 'options'
>>> 

As a side-note, you should also avoid using the string module, there are some deprecated functions there, split() is one of them, see here.

@s0undt3ch
Copy link
Collaborator

Also, have a look.

root@pedro-ubuntu-test:~# ls -lah /tmp/tarfile.tar.gz
ls: cannot access /tmp/tarfile.tar.gz: No such file or directory

There's no tar file yet.
Let's create it

root@pedro-ubuntu-test:~# salt-call archive.tar czf /tmp/tarfile.tar.gz /etc
[INFO    ] Package debconf-utils is not installed.
[INFO    ] Executing command 'tar -czf /tmp/tarfile.tar.gz /etc' in directory '/root'
local:
    - tar: Removing leading `/' from member names

Does it exist?

root@pedro-ubuntu-test:~# ls -lah /tmp/tarfile.tar.gz
-rw-r--r-- 1 root root 637K Sep 14 15:20 /tmp/tarfile.tar.gz

Yep, it does. Let's see it's contents.

root@pedro-ubuntu-test:~# tar -ztvf /tmp/tarfile.tar.gz
drwxr-xr-x root/root         0 2013-09-14 10:38 etc/
-rw-r--r-- root/root       267 2012-07-03 17:07 etc/legal
-rw-r--r-- root/root       880 2013-03-07 02:00 etc/hosts.deny
drwxr-xr-x root/root         0 2012-10-24 00:32 etc/lsb-base/
-rw-r--r-- root/root        73 2013-03-07 01:55 etc/shells
-rw-r--r-- root/root        45 2012-06-17 19:08 etc/bash_completion
drwxr-xr-x root/root         0 2013-09-08 10:33 etc/subversion/
-rw-r--r-- root/root      6692 2013-06-21 22:12 etc/subversion/config
-rw-r--r-- root/root      7679 2013-06-21 22:12 etc/subversion/servers
-rw-r--r-- root/root       887 2012-07-03 15:11 etc/rpc
-rw-r--r-- root/root        99 2013-04-19 08:47 etc/lsb-release
drwxr-xr-x root/root         0 2013-07-12 21:09 etc/rc3.d/
lrwxrwxrwx root/root         0 2013-07-12 21:09 etc/rc3.d/S20nova-agent -> ../init.d/nova-agent
lrwxrwxrwx root/root         0 2013-03-07 01:55 etc/rc3.d/S99rc.local -> ../init.d/rc.local
-rw-r--r-- root/root       677 2013-01-30 12:58 etc/rc3.d/README
lrwxrwxrwx root/root         0 2013-03-07 02:00 etc/rc3.d/S70dns-clean -> ../init.d/dns-clean
lrwxrwxrwx root/root         0 2013-07-12 21:07 etc/rc3.d/S14xe-linux-distribution -> ../init.d/xe-linux-distribution
lrwxrwxrwx root/root         0 2013-03-07 01:55 etc/rc3.d/S75sudo -> ../init.d/sudo
lrwxrwxrwx root/root         0 2013-03-07 01:55 etc/rc3.d/S99ondemand -> ../init.d/ondemand
lrwxrwxrwx root/root         0 2013-03-07 02:00 etc/rc3.d/S50rsync -> ../init.d/rsync
lrwxrwxrwx root/root         0 2013-03-07 02:00 etc/rc3.d/S70pppd-dns -> ../init.d/pppd-dns
lrwxrwxrwx root/root         0 2013-03-07 02:01 etc/rc3.d/S99grub-common -> ../init.d/grub-common
lrwxrwxrwx root/root         0 2013-03-07 01:55 etc/resolv.conf.1378629434.bak~ -> ../run/resolvconf/resolv.conf
-rw-r--r-- root/root       346 2012-05-01 02:08 etc/discover-modprobe.conf
-rw-r--r-- root/root        92 2012-10-28 03:43 etc/host.conf

------------------------- removed for simplicity -------------------------

lrwxrwxrwx root/root         0 2013-09-08 08:43 etc/alternatives/java.1.gz -> /usr/lib/jvm/java-7-openjdk-amd64/jre/man/man1/java.1.gz
lrwxrwxrwx root/root         0 2013-09-08 08:40 etc/alternatives/fakeroot.fr.1.gz -> /usr/share/man/fr/man1/fakeroot-sysv.1.gz
lrwxrwxrwx root/root         0 2013-03-07 01:57 etc/alternatives/rename.1.gz -> /usr/share/man/man1/prename.1.gz
lrwxrwxrwx root/root         0 2013-03-07 02:00 etc/alternatives/editor.1.gz -> /usr/share/man/man1/nano.1.gz
lrwxrwxrwx root/root         0 2013-03-07 02:00 etc/alternatives/telnet.1.gz -> /usr/share/man/man1/telnet.netkit.1.gz
lrwxrwxrwx root/root         0 2013-09-08 08:43 etc/alternatives/servertool.1.gz -> /usr/lib/jvm/java-7-openjdk-amd64/jre/man/man1/servertool.1.gz
lrwxrwxrwx root/root         0 2013-09-08 08:40 etc/alternatives/cpp -> /usr/bin/cpp

It worked...

root@pedro-ubuntu-test:~# tar --version
tar (GNU tar) 1.26
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by John Gilmore and Jay Fenlason.

What is your distro?
And your version of tar?
Can you please also paste the output of salt --versions-report for both the master and the clent minion machine?

@phpcool
Copy link
Author

phpcool commented Sep 14, 2013

distro info:CentOS release 6.4 (Final)

kernel info:Linux client 2.6.32-358.14.1.el6.x86_64 #1 SMP Tue Jul 16 23:51:20 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

tar info:
tar (GNU tar) 1.23
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

salt info:
Salt: 0.16.0
Python: 2.6.6 (r266:84292, Jul 10 2013, 22:48:45)
Jinja2: unknown
M2Crypto: 0.20.2
msgpack-python: 0.1.13
msgpack-pure: Not Installed
pycrypto: 2.0.1
PyYAML: 3.10
PyZMQ: 2.2.0.1
ZMQ: 3.2.3


so,when i run "salt 'client' archive.tar czf /tmp/tarfile.tar.gz /etc", and i edited “/usr/lib/python2.6/site-packages/salt/modules/archive.py” of 'client' minion, like this:
sourcefiles = ' '.join(sources)
+print sourcefiles
+print cwd
cmd = 'tar -{0} {1} {2}'.format(options, tarfile, sourcefiles)

master run result:
- tar: Cowardly refusing to create an empty archive
- Try tar --help' ortar --usage' for more information.

minion output:
null line
/etc

so sourcefiles=null,and cwd='/etc'? why?
thx for s0undt3ch's answer.

@terminalmage
Copy link
Contributor

Please try to use more descriptive issue names. I have edited the name of this post to better reflect its details.

@phpcool
Copy link
Author

phpcool commented Sep 15, 2013

@terminalmage OK,thx.

@phpcool
Copy link
Author

phpcool commented Sep 18, 2013

UP~

@terminalmage
Copy link
Contributor

Sorry, I don't understand what you're trying to say.

@terminalmage
Copy link
Contributor

Looking at https://github.com/saltstack/salt/blob/v0.16.0/salt/modules/archive.py#L19, there are two positional arguments (cwd and template) which come before the *sources. This is why there are no sources when you run the command. The documentation reflects the current state of the develop branch.

As it was already explained by @s0undt3ch, in the develop branch this function has been changed. sources no longer uses the asterisk, and must be passed as a comma-separated list. Its position is also now before cwd and template.

This fix will be in 0.17.0. Testing from the latest code in the develop branch, the command you used works. As this has been fixed, I am closing this.

@phpcool
Copy link
Author

phpcool commented Sep 20, 2013

OK,thx

@mahul
Copy link

mahul commented Oct 5, 2013

archive.tar cannot be used to untar a file in its current form as it requires 'sources' which is not required in untar. Am I missing something here?

@s0undt3ch
Copy link
Collaborator

@mahul you're missing archive.untar. 😄

@s0undt3ch
Copy link
Collaborator

Heh, stupid of me.... forget that @mahul

s0undt3ch added a commit to s0undt3ch/salt that referenced this issue Oct 5, 2013
techhat added a commit that referenced this issue Oct 5, 2013
Properly support decompressing `tar` files. Refs #7244.
s0undt3ch added a commit to s0undt3ch/salt that referenced this issue Oct 5, 2013
@s0undt3ch
Copy link
Collaborator

@mahul The 0.17.1 version of salt will include the fix which allows you to properly decompress tar files. Thanks for your report.

@mahul
Copy link

mahul commented Oct 7, 2013

@s0undt3ch - thanks very much!

@s0undt3ch
Copy link
Collaborator

Anytime!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior
Projects
None yet
Development

No branches or pull requests

4 participants