Beispiel #1
0
 def test_create_association_runid(self):
     """Create mac config with run_id; return results object."""
     mac = '00:00:00:00:00:02'
     mac_file = '01-00-00-00-00-00-02'
     tftp = SpokeTFTP(self.tftp_root)
     expected_result = [[mac_file]]
     result = tftp.create(mac, self.template, self.run_id)['data']
     tftp.delete(mac)
     self.assertEqual(result, expected_result)
Beispiel #2
0
 def test_create_association_runid(self):
     """Create mac config with run_id; return results object."""
     mac = '00:00:00:00:00:02'
     mac_file = '01-00-00-00-00-00-02'
     tftp = SpokeTFTP(self.tftp_root)
     expected_result = [[mac_file]]
     result = tftp.create(mac, self.template, self.run_id)['data']
     tftp.delete(mac)
     self.assertEqual(result, expected_result)
Beispiel #3
0
    def tearDown(self):
        """Delete test tftp file structure."""
        tftp = SpokeTFTP(self.tftp_root)
        tftp.delete(self.mac)
        if os.path.exists(self.tftp_dir + self.template):
            os.remove(self.tftp_dir + self.template)

        for d in self.tftp_dir, self.tftp_root:
            if (os.path.exists(d)):
                try:
                    os.removedirs(d)
                except Exception as e:
                    raise e
Beispiel #4
0
 def tearDown(self):
     """Delete test tftp file structure."""
     tftp = SpokeTFTP(self.tftp_root)
     tftp.delete(self.mac)
     if os.path.exists(self.tftp_dir + self.template):
         os.remove(self.tftp_dir + self.template)
     
     for d in self.tftp_dir, self.tftp_root:
         if (os.path.exists(d)):
             try:
                 os.removedirs(d)
             except Exception as e:
                 raise e
Beispiel #5
0
 def test_get_all_macs_templates(self):
     """Search for all macs and templates; return list."""
     # macs should be returned as lower case, with s/:/- and with prefix
     raw_mac1 = '00-0c-29-57-3b-31'
     raw_mac3 = '00-00-00-00-00-03'
     raw_mac4 = '00-00-00-00-00-04'
     template = self.template
     template2 = 'newtemplate.template'
     open(self.tftp_dir + template2, 'w').close()
     tftp = SpokeTFTP(self.tftp_root)
     tftp.create(raw_mac3, template2)
     tftp.create(raw_mac4, template2)
     result = tftp.search()['data']
     expected_result = [{'templates' : [template2, template], 'configs' : [raw_mac3, raw_mac4, raw_mac1]}]
     tftp.delete(raw_mac3)
     tftp.delete(raw_mac4)
     os.remove(self.tftp_dir + template2)
     self.assertEqual(result, expected_result)
Beispiel #6
0
 def test_get_all_macs_templates(self):
     """Search for all macs and templates; return list."""
     # macs should be returned as lower case, with s/:/- and with prefix
     raw_mac1 = '00-0c-29-57-3b-31'
     raw_mac3 = '00-00-00-00-00-03'
     raw_mac4 = '00-00-00-00-00-04'
     template = self.template
     template2 = 'newtemplate.template'
     open(self.tftp_dir + template2, 'w').close()
     tftp = SpokeTFTP(self.tftp_root)
     tftp.create(raw_mac3, template2)
     tftp.create(raw_mac4, template2)
     result = tftp.search()['data']
     expected_result = [{
         'templates': [template2, template],
         'configs': [raw_mac3, raw_mac4, raw_mac1]
     }]
     tftp.delete(raw_mac3)
     tftp.delete(raw_mac4)
     os.remove(self.tftp_dir + template2)
     self.assertEqual(result, expected_result)
Beispiel #7
0
def delete(mac=None):
    '''
    Delete a config for a specific MAC

    CLI Examples::

        salt '*' tftp.delete mac='11:22:33:44:55:66'
    '''
    if mac is None:
        return "mac must be specified"
    try:
        conf = _spoke_config(_salt_config('config'))
        tftproot = conf.get("TFTP", "tftp_root")
        tftp = SpokeTFTP(tftproot)
        result = tftp.delete(mac)
    except error.SpokeError as e:
        result = common.handle_error(e)
    return result
Beispiel #8
0
 def test_delete_mac(self):
     """Delete a config; return True."""
     tftp = SpokeTFTP(self.tftp_root)
     self.assertTrue(tftp.delete(self.mac))
     tftp.create(self.mac, self.template)
Beispiel #9
0
 def test_delete_mac(self):
     """Delete a config; return True."""
     tftp = SpokeTFTP(self.tftp_root)
     self.assertTrue(tftp.delete(self.mac))
     tftp.create(self.mac, self.template)
Beispiel #10
0
        try:
            mac = request['data']['mac']
        except KeyError:
            mac = None
        try:
            target = request['data']['target']
        except KeyError:
            target = None
        try:
            mc.data = tftp.search(mac=mac, target=target)
        except error.SpokeError as e:
            mc.fail(e.msg, e.exit_code)
    elif request['action'] == 'create':
        mac = request['data']['mac']
        target = request['data']['target']
        try:
            mc.data = tftp.create(mac, target)
        except error.SpokeError as e:
            mc.fail(e.msg, e.exit_code)
    elif request['action'] == 'delete':
        mac = request['data']['mac']
        try:
            mc.data = tftp.delete(mac)
        except error.SpokeError as e:
            mc.fail(e.msg, e.exit_code)
    else:
        msg = "Unknown action: " + request['action']
        mc.fail(msg, 2)
    log.info('Result via Mcollective: %s' % mc.data)
    sys.exit(0)